News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Rich Edit Control

Started by Zen, July 23, 2015, 09:02:10 AM

Previous topic - Next topic

Zen

This question is REALLY dumb,...but, I can't get it right. :dazzled:
I have used the macros in dialog.inc to create a dialog box for my app. It has a rich edit control to allow the user to enter data.
Anyway, I read the MSDN documentation, and I wrote a Dialog Proc for the dialog box, and everything works great,...except for a minor detail.
When the user enters his data into the control, I call a procedure that validates the format of the string. This procedure checks for every conceivable error and returns specific error codes to indicate the type of error. If the user makes a mistake, I call SendMessage to put a message about the error in the rich edit control and RETURN before calling EndDialog. This is simple and works.
...But, when I post the error message in the rich edit control, I change the font color to red, to indicate ERROR. This also is simple and works as expected. And, here's the silly part: I then try to set the font color back to black for the next entry into the rich edit control,...but, I can't get it to work. Every text item displayed in the rich edit control from that moment until the Validate procedure returns a SUCCESS code and calls End Dialog, is RED.
...It's one of those DUMB things that I don't really even care about,...but, that drives me nuts,...

jj2007

Without seeing any code, this is difficult. Do you have something similar to the following?

.if CharFtMask==CFM_COLOR
  mov charfmt.crTextColor, eax
  mov eax, CFE_AUTOCOLOR
  or charfmt.dwEffects, eax ; get rid of CFE_AUTOCOLOR
  xor charfmt.dwEffects, eax
...
invoke SendMessage, hRichEdit, EM_SETCHARFORMAT, SCF_SELECTION, ADDR charfmt


There is also the option to insert a piece of RTF text.

dedndave

Quote from: Zen on July 23, 2015, 09:02:10 AM
And, here's the silly part: I then try to set the font color back to black for the next entry into the rich edit control,...but, I can't get it to work. Every text item displayed in the rich edit control from that moment until the Validate procedure returns a SUCCESS code and calls End Dialog, is RED.

ummmm....
sounds to me like the code is doing exactly what you programmed it to do
maybe rethink the color-change /  error logic ?

Zen

JOCHEN and DAVE,   
...Yeah,...you're BOTH right.
I neglected to mention in my original post (I was pressed for time) that all the code that I'm using to post the error messages in the Rich Edit control, and change the font color, exists in a very simple Dialog Procedure that handles just two messages: WM_INITDIALOG and the message that is sent when the user presses the button on the Dialog Box (wParam of WM_COMMAND), indicating that the data should be processed.   
To set the color I initialize the CHARFORMATA structure and invoke SendMessage (to the Dialog Box with the EM_SETCHARFORMAT message).   
I think,...to get the font color back to black, I need to call the code from some location OUTSIDE of the Dialog Proc,...:icon_eek:
I just thought it would be a relatively simple operation, like calling SetTextColor. This doesn't work, by the way,...

Hey,...I'm just going to forget about it,...it's just an annoyance,...

jj2007

One simple thing you can try is to replace SendMessage with PostMessage. The RichEdit control is sometimes not ready to receive messages, and posting instead of sending may help.