Wm_ctlcoloredit

This is a discussion on Wm_ctlcoloredit within the Windows Programming forums, part of the Platform Specific Boards category; Hello, I have an edit control on my dialog, I have handled WM_CTLCOLOREDIT to change the edit control's color. However, ...

  1. #1
    Registered User
    Join Date
    Apr 2004
    Posts
    102

    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

  2. #2
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    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.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  3. #3
    Registered User
    Join Date
    Jan 2005
    Posts
    847
    I don't know if it will help but maybe you could just send EM_SETBKGNDCOLOR thats assuming you have a rich edit control.

  4. #4
    Registered User
    Join Date
    Apr 2004
    Posts
    102
    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.

  5. #5
    Registered User
    Join Date
    Apr 2004
    Posts
    102
    ha ha, sorry I only just realised I forgot to attach the file.. I must have one heck of a short memory

    here it is: (please remove txt extension, it wouldn't allow me to attach a zip)
    Attached Files Attached Files

  6. #6
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    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?
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  7. #7
    Registered User
    Join Date
    Apr 2004
    Posts
    102
    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.

  8. #8
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    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.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  9. #9
    Registered User
    Join Date
    Apr 2004
    Posts
    102
    Thank you very much.

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21