简体   繁体   中英

Changing background color of an

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM