Thread: WM_CTLCOLORSTATIC and Read Only Edit Controls

  1. #1
    Registered User
    Join Date
    Jul 2009
    Posts
    4

    WM_CTLCOLORSTATIC and Read Only Edit Controls

    Hi, I'm having confusion with the effect of the return value of WM_CTLCOLORSTATIC with read only edit controls.

    In my main WndProc's WM_CREATE's handler includes:

    Code:
    hwndInfoEdit = CreateWindowEx(NULL, TEXT("edit"), NULL, WS_CHILD | WS_VISIBLE | 
    			      ES_MULTILINE | ES_AUTOVSCROLL |
    			      ES_READONLY, 25, 25, 25, 25, hWnd, NULL,
    			      ((LPCREATESTRUCT)lParam) -> hInstance, NULL);
    Which should create a read only edit control.

    I also handled WM_CTLCOLORSTATIC in the same WndProc:

    Code:
    case WM_CTLCOLORSTATIC:
    		{
    			HDC hdcStatic = (HDC)wParam;
    			HWND hwndStatic = (HWND)lParam;
    
    			if(hwndStatic == hwndInfoEdit)
    			{
    				MessageBeep(0);
    				return (LRESULT)GetStockObject(BLACK_BRUSH);
    			}
    		}
    The MessageBeep did play a beep, so I'm sure the return line after that did run.

    But for some reason, the edit control's background color is white. I returned a handle to a black brush, so why did it turn out white? I replaced BLACK_BRUSH with GRAY_BRUSH and a few other values, but it still makes the background color white.

    I tried including a SetBkColor(hdcStatic, RGB(0,0,0)); before the return and that made the background black, but I'm trying to understand why I can't use the return to get a black background.

    Please reply, any help is greatly appreciated.

  2. #2
    Registered User Joelito's Avatar
    Join Date
    Mar 2005
    Location
    Tijuana, BC, México
    Posts
    310
    I think you need to use SetBkMode.
    * PC: Intel Core 2 DUO E6550 @ 2.33 GHz with 2 GB RAM: Archlinux-i686 with xfce4.
    * Laptop: Intel Core 2 DUO T6600 @ 2.20 GHz with 4 GB RAM: Archlinux-x86-64 with xfce4.

  3. #3
    Registered User
    Join Date
    Jul 2009
    Posts
    4
    Thanks a lot, problem fixed. I added SetBkMode(hdcStatic, TRANSPARENT); before the return, and the background changed according to the return. Thanks again.

Popular pages Recent additions subscribe to a feed