Static text box background color?

Starting to dive into the WIN32 API (windows.h) and I've noticed that static text boxes have a grey BG and editable text boxes are white. I suppose this is because the static one is "greyed out" because it's to remain static and not change it's value.

The problem is I am using a static text box as a label to store user entered info into it via a WM_COMMAND. That all works just fine but it looks pretty ugly being greyed out on my white bg window. Is there a Label handle that I should use instead of using static text boxes? If not, how do I change the bg color of a static text field?
when you play with windows api, always - I mean, ALWAYS - refer first to MSDN for official description, especially remarks section.

When reading:
http://msdn.microsoft.com/en-us/library/windows/desktop/bb760769%28v=vs.85%29.aspx
You can track message:
http://msdn.microsoft.com/en-us/library/windows/desktop/bb787524%28v=vs.85%29.aspx
and even see example.

So if this is my handle declaration. How would I implent this?
1
2
3
4
		textLabel = CreateWindow("EDIT", textSaved,
			WS_VISIBLE | WS_CHILD | WS_BORDER,
			5, 5, 474, 190,
			hwnd, NULL, NULL, NULL);


I'm getting an "Error: argument of type "HWND" is incompatible with parameter of type "HDC" when trying to use

 
SetBkColor(textLabel, RGB(0, 0, 0));
you should use SetBkColor(textLabel, RGB(0, 0, 0)); in winproc. First parameter is not HANDLE but HDC.

Like in example i posted above:
1
2
3
4
5
6
7
8
9
10
11
12
   case WM_CTLCOLORSTATIC:
        {
        HDC hdcStatic = (HDC) wParam;
        SetTextColor(hdcStatic, RGB(255,255,255));
        SetBkColor(hdcStatic, RGB(0,0,0));

        if (hbrBkgnd == NULL)
        {
            hbrBkgnd = CreateSolidBrush(RGB(0,0,0));
        }
        return (INT_PTR)hbrBkgnd;
        }
If what you are trying to do is change the background color of a "static" (label) control, you need to use the WM_CTLCOLORSTATIC message for that. Its just a bit complicated, but I can provide an example if you need it.
Yeah I'm not really seeing where to utilize this code with my own. As you can see I have the textLabel handle. Outside of that I'm not sure where to use this WM_CTLCOLORSTATIC code
Your program must have a Window Procedure. If you've created child window controls on your main program window, Windows (the Operating System) will send WM_CTLCOLORSTATIC messages to the parent window's Window Procedure. Here is what MSDN says (just as tath told you to look up)...


A static control, or an edit control that is read-only or disabled, sends the WM_CTLCOLORSTATIC message to its parent window when the control is about to be drawn. By responding to this message, the parent window can use the specified device context handle to set the text and background colors of the static control.

WM_CTLCOLORSTATIC
hdcStatic = (HDC) wParam; // handle to display context
hwndStatic = (HWND) lParam; // handle to static control

Parameters
hdcStatic
Value of wParam. Handle to the device context for the static control window.
hwndStatic
Value of lParam. Handle to the static control.



You need to handle the WM_CTLCOLORSTATIC message. In doing that you create an HBRUSH of the color you want to color the background of the control. That HBRUSH gets returned by the Window Procedure. As Windows messages go, its a bit unusual. That's why I said its a bit tricky and involved.
I did look it up (just as tath told me to do)....

I was saying I cant understand how to implement it. Don't just assume I didn't look into it because I can't understand it.
Sorry CGunn86. Windows Api coding, as well as using any class framework code to wrap it in the hope of making it easier, takes awhile to master. By 'awhile', I mean like x number of months, where x is typically something like 6. Would you like if I posted a very simple and compilable program with just a couple text boxes and labels on it that show how to do it?
Topic archived. No new replies allowed.