0

In my Win32 program written in C++, I have defined a bunch of child windows to display some text, thus:

hnd_to_this_ch_window = CreateWindow( 
                        L"EDIT",L"Some initial text", WS_VISIBLE | WS_CHILD | ES_LEFT,  
                        position_of_this_window_X,              
                        position_of_this_window_Y,
                        TEXTOUT_DEFAULT_WIDTH,          
                        TEXTOUT_DEFAULT_HEIGHT, 
                        handle_to_my_parent_window, NULL,                        
                        hinstance_variable_used_by_create_window, 
                        NULL )

I need to be able to change their background color to red with one call, and then back to white (or, perhaps, another color) with another call. I can't seem to find any answers for how to do that with one function call (similar to how I just use SetWindowText() to change values displayed inside these child windows.

a1s2d3f4
  • 589
  • 4
  • 7
  • 18
  • I think this may help you find a solution to your problem. http://stackoverflow.com/a/10063734/5162587 – E-rap Jul 30 '15 at 18:54
  • @E-rap Unless I am mistaken, this example seems to deal with setting the window background color when you register the window class. It doesn't explain how to do it during run-time. – a1s2d3f4 Jul 31 '15 at 03:37

1 Answers1

0

The edit control sends the WM_CTLCOLOR message to its parent window when it is about to be painted. You control the text and background colors by handling this message. So you can't control the colors with one API call, you have to set variables to remember the colors you want, then change or invalidate the edit control to cause it to repaint, then use those variables in WM_CTLCOLOR.

ScottMcP-MVP
  • 10,337
  • 2
  • 15
  • 15
  • Would you mind giving me very basic code example, so I can fill in the details myself? I am assuming it all begins with some kind of function call anyway. What would it be? – a1s2d3f4 Jul 31 '15 at 03:38