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

后端 未结 2 1558
故里飘歌
故里飘歌 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 08:59

    If you want a customized window you can create your own window class to draw that type of window. Implement a handler for wm_paint and draw whatever you want for the window. There are a lot of tutorials available.

    0 讨论(0)
  • 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;
    
    0 讨论(0)
提交回复
热议问题