开发者

Set background color of a control? (WinAPI)

开发者 https://www.devze.com 2023-01-04 18:08 出处:网络
How can I set the backcolor of a control (equivilant of control.backcol开发者_如何学Goor in .Net). I tried setBKColor with no luck.

How can I set the backcolor of a control (equivilant of control.backcol开发者_如何学Goor in .Net). I tried setBKColor with no luck.

ex: TabHwnd = createWindowEx(NULL,WC_TAB....

then how could I set the back color of TabHwnd?

Thanks


Windows will generate a message when it's painting the background of a control, and it is up to your program to respond to the message appropriately.

  • WM_CTLCOLORBTN
  • WM_CTLCOLOREDIT
  • WM_CTLCOLORDLG
  • WM_CTLCOLORLISTBOX
  • WM_CTLCOLORSCROLLBAR
  • WM_CTLCOLORSTATIC


I know this question is old, but perhaps this answer will still help some others.

What worked for me was to return a hollow brush for the background color messages. For example:

switch (msg) {
  case WM_CTLCOLORDLG:
    return (INT_PTR)GetStockObject(HOLLOW_BRUSH);
  case WM_CTLCOLORSTATIC:
    return (INT_PTR)GetStockObject(HOLLOW_BRUSH);
}

Also, you don't need to worry about deleting the "brushes" created by GetStockObject.


Try subclassing (see SetClassLong) and process WM_ERASEBKGND

0

精彩评论

暂无评论...
验证码 换一张
取 消