Winapi中两个静态文本元素的不同背景色

时间:2018-07-20 12:21:26

标签: c++ winapi text colors static

如何分别更改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;

1 个答案:

答案 0 :(得分:1)

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

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