Hi Guys
I´m trying to enable and disabled a richeditcontrol using GetWindowLong and ES_READONLY, but it is not working.
I inserted a richeditcontrol on a dialog. This richedit control have his own background color settled by EM_SETBKGNDCOLOR
I´m trying to use &ES_READONLY to alternate in between enabled and disabled.
For example, whenever i press a button (Enabled), it allows editing of the text on the richedit control
And when pressing Disabled it shoulw disabled the edition. But i´m not being able to do this
I tried this pseudo code:
If BtnEnabled = TRUE
call 'USER32.GetWindowLongA' D@hREdit, &GWL_STYLE
Test_If eax &ES_READONLY
xor eax &ES_READONLY
Test_End
call 'user32.SetWindowLongA' D@hREdit, &GWL_STYLE, eax
Endif
If BtnDisabled = &TRUE
call 'USER32.GetWindowLongA' D@hREdit, &GWL_STYLE
or eax &ES_READONLY
call 'user32.SetWindowLongA' D@hREdit, &GWL_STYLE, eax
Endif
But it is not working.
It only works if i create the richedit control (from the resources) with the ES_READONLY flag settled (But cannot enabled programmatically either)
Hi Guga!
Why not EnableWindow?
Quote from: HSE on October 12, 2020, 10:12:44 AM
Hi Guga!
Why not EnableWindow?
Hi HSE, because if i use EnableWindow, the background color of the RichEdit Control won´t show anymore. The bgcolor of the richeditcontropl is, for example, yellow. I want it to remain yellow even if the control is disabled. The problem is that i´m not being able to disabled the control programatically and also keeping the bgcolor
Then you have to subclass RichEdit and to capture events in subclass :eusa_boohoo:
- protect the entire text
- return TRUE to the EN_PROTECTED notification
more (https://www.codeguru.com/cpp/controls/richedit/article.php/c2401/Setting-selected-text-to-readonly.htm)
Quote from: jj2007 on October 12, 2020, 06:18:51 PM
- protect the entire text
- return TRUE to the EN_PROTECTED notification
more (https://www.codeguru.com/cpp/controls/richedit/article.php/c2401/Setting-selected-text-to-readonly.htm)
Hi JJ and HSE, many tks.
JJ, i read the links and found another message that can be used when trying to find the GetEvenMask api (It works only with RichEdit ole, right ?. I don´t know how to use RichEdit in Ole) and it seems to work only with Vista.
Then i found this: http://computer-programming-forum.com/82-mfc/1302f222e23246ff.htm that provided an alternative way handling the WM_ENABLE message and overriding the WM_CHAR, WM_SETFOCUS message to simulate a
disabled RTF box. But this also could be too overhead
Since i don´t know how to use RichEditOle and the other alternative (WM_ENABLE) etc, seem too much code for a simple function, i ended up using EM_SETREADONLY passed with sendmessage :smiley:
...If D@Message = &WM_INITDIALOG
lea eax D@hStringList
call SetupLibRichEdit D@Adressee, IDC_EDIT_STRINGS, eax
call InitStringsList D@hStringList, D$StringsList
If D$WhatRsrcControlsCommand = RSRC_DELETE_VALUE
mov eax {B$ "Strings Delete", 0}
call 'USER32.SetWindowTextA' D@Adressee, eax
call 'User32.SetDlgItemTextA' D@Adressee, &IDOK, {B$ "Delete", 0}
call 'USER32.SendMessageA' D@hStringList, &EM_SETREADONLY , &TRUE, 0 ; <--------- Enable read only if The Menu Option "Delete Strings is selected)
Else_If D$WhatRsrcControlsCommand = RSRC_SAVE_VALUE
mov eax {B$ "String Save to Disk", 0}
call 'USER32.SetWindowTextA' D@Adressee, eax
call 'User32.SetDlgItemTextA' D@Adressee, &IDOK, {B$ "Save", 0}
call 'USER32.SendMessageA' D@hStringList, &EM_SETREADONLY , &TRUE, 0 ; <--------- Enable read only if The Menu Option "Save Strings is selected)
Else
mov eax {B$ "String View", 0}
call 'USER32.SetWindowTextA' D@Adressee, eax
call 'User32.SetDlgItemTextA' D@Adressee, &IDOK, {B$ "Ok", 0}
call 'USER32.SendMessageA' D@hStringList, &EM_SETREADONLY , &FALSE, 0 ; <--------- Disable read only in all other cases (for editing, viewing)
End_If
call 'USER32.SetClassLongA' D@Adressee &GCL_HICON D$wc_hIcon
The EM_SETREADONLY also works on XP or only for vista and above (As getevenmask seems to do) ?
Good solution, Guga (and it works on XP, too) :thumbsup:
Works but more complicated:
invoke SendMessage, hRichEdit, EM_SETEVENTMASK, 0, ENM_PROTECTED
invoke SendMessage, hRichEdit, EM_SETCHARFORMAT, SCF_ALL, esp
... in WndProc:
.if uMsg_==WM_NOTIFY
mov edx, lParam_ ; Pointer to NOTIFY structure
mov eax, [edx.NMHDR.code]
.if [edx.NMHDR.code]==EN_PROTECTED
or eax, -1
ret ; bypass DefWindowProc
.endif
.endif