【问题标题】:Winapi different background colors for two static text elementsWinapi 两个静态文本元素的不同背景颜色
【发布时间】:2018-12-28 18:15:44
【问题描述】:

如何分别更改 2 个静态文本元素的背景颜色,每个元素都有不同的背景颜色

代码:

background1 = CreateWindow("STATIC","",WS_VISIBLE | WS_CHILD , 0,0,800,20, hwnd , NULL, NULL, NULL);
background2 = CreateWindow("STATIC","",WS_VISIBLE | WS_CHILD , 0,70,800,500, hwnd , NULL, NULL, NULL);


case WM_CTLCOLORSTATIC:
    {  
         HDC hdcStatic = (HDC) wParam;
         SetTextColor(hdcStatic, RGB(0,0,255));
         SetBkColor(hdcStatic, RGB(0,0,255));

         if (hbrBkgnd == NULL){
             hbrBkgnd = CreateSolidBrush(RGB(0,0,55));
         }
         return (INT_PTR)hbrBkgnd;
    }
break;

【问题讨论】:

    标签: c++ winapi text colors static


    【解决方案1】:

    lparam 包含一个静态控件窗口句柄,因此您可以检查它以确定正在重绘的控件。

    if(reinterpret_cast<::HWND>(lParam) == background1)
    {
        // set background for control 1...
    }
    else // set backgrounds for other controls
    

    【讨论】:

      猜你喜欢
      • 2022-01-14
      • 1970-01-01
      • 2014-04-29
      • 2016-02-28
      • 1970-01-01
      • 1970-01-01
      • 2012-01-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多