-
Wm_ctlcoloredit
Hello, I have an edit control on my dialog, I have handled WM_CTLCOLOREDIT to change the edit control's color. However, I have just noticed a bug, when highlighting the text/erasing it, it doesn't repaint till I type something else. I don't really understand why this is happening.
This is how I handle the message:
Code:
case WM_CTLCOLOREDIT:
SetBkMode((HDC)wParam,TRANSPARENT);SetTextColor((HDC)wParam,RGB(0,0,200));
return (BOOL) BackgroundBrush;
Any help will be greatly appreciated, thanks
-
Your WM_CTLCOLOREDIT handler looks fine. Have you tried creating a very simple example that replicates the problem? If you have/do and still can't resolve it then post that example code.
-
I don't know if it will help but maybe you could just send EM_SETBKGNDCOLOR thats assuming you have a rich edit control.
-
I have attatched a small sample program source code that has the same problem. Hopefully after seeing the problem first hand you will know how to fix it.
I have found out the problem line, it is 'SetBkMode((HDC)wParam,TRANSPARENT)' however, I still don't know how to fix it.
Thank you.
-
ha ha, sorry I only just realised I forgot to attach the file.. I must have one heck of a short memory :D
here it is: (please remove txt extension, it wouldn't allow me to attach a zip)
-
Looks good to me - the background colour should change to the system highlight colour when you highlight any text in the edit, which your example does.
Is that the behaviour (highlight) you wish to change?
-
sorry, I must have not explained the problem good enough.
with that code, when I use the backspace, the text doesn't get erased untill I try to highlight it. basically, the edit control is not repainting when it should do.
does this bug not happen with you? if not, that's really strange.
-
Sorry, didn't notice that - but have now you've mentioned it. :)
Since it's a single colour your using, use SetBkColor to set the background colour and it should work as intended; if you're using a non-uniform brush, such as an image, and need to use SetBkMode then invalidate the control (InvalidateRect) in response to an EN_CHANGE notification message.
-