简体   繁体   English

更改背景色

[英]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: 在用C ++编写的Win32程序中,我定义了一堆子窗口来显示一些文本,因此:

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. 我似乎找不到通过一个函数调用来完成此操作的任何答案(类似于我只是使用SetWindowText()来更改这些子窗口中显示的值的方式)。

The edit control sends the WM_CTLCOLOR message to its parent window when it is about to be painted. 编辑控件将要绘制时,将WM_CTLCOLOR消息发送到其父窗口。 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. 因此,您无法使用一个API调用来控制颜色,必须设置变量以记住所需的颜色,然后更改或使编辑控件无效以使其重新绘制,然后在WM_CTLCOLOR中使用这些变量。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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