c++ win32: how to set back color of a window?

后端 未结 2 1557
故里飘歌
故里飘歌 2021-01-24 08:42

I can set the back color when i am registering the class, e.g.:

wincl.hbrBackground = CreateSolidBrush(RGB(202, 238, 255));
RegisterClassEx(&wincl);
<         


        
2条回答
  •  礼貌的吻别
    2021-01-24 09:07

    All the windows controls send a message to their parent to get the brush to use to fill their background. Assuming you save a copy of the brush handle somewhere, you can do the following in your WindowProc, or DialogProc, to ensure everything draws with the correct background brush.

    case WM_CTLCOLORSTATIC:
    case WM_CTLCOLORBTN:
      HDC hdc;
      HWND hwndCtl;
      POINT pt;
      hdc = (HDC)wParam;
      hwndCtl = (HWND)lParam;
      pt.x = 0;
      pt.y = 0;
      MapWindowPoints(hwndCtl,_hwnd,&pt,1);
      x = -pt.x;
      y = -pt.y;
      SetBrushOrgEx(hdc,x,y,NULL);
      return (INT_PTR)_skinBrush;
    

提交回复
热议问题