1、使用画刷将整个界面初始化为黑色
wndclass.hbrBackground = CreateSolidBrush(0);
2、WM_CREATE创建窗口的时候
hIns = (HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE); hwndRect = CreateWindow(L"static", L"", WS_VISIBLE|WS_CHILD|SS_WHITERECT, 0, 0, 0, 0, hwnd, (HMENU)9, hIns, NULL); for (int i = 0; i < 3; ++i) { hwndScroll[i] = CreateWindow(L"scrollbar", L"", WS_VISIBLE|WS_CHILD|SBS_VERT|WS_TABSTOP, 0,0,0,0,hwnd,(HMENU)i, hIns, NULL); hwndLabel[i] = CreateWindow(L"static", szColorLabel[i], WS_VISIBLE|WS_CHILD|SS_CENTER,0,0,0,0,hwnd,(HMENU)(i+3), hIns,NULL); hwndValue[i] = CreateWindow(L"static",L"0",WS_VISIBLE|WS_CHILD|SS_CENTER,0,0,0,0,hwnd,(HMENU)(i+6),hIns,NULL); SetScrollRange(hwndScroll[i], SB_CTL, 0, 255, FALSE); SetScrollPos(hwndScroll[i], SB_CTL, 0, FALSE); OldScroll[i] = (WNDPROC)SetWindowLong(hwndScroll[i], GWL_WNDPROC, (LONG)ScrollProc); hBrush[i] = CreateSolidBrush(crPrim[i]); } hBrushStatic = CreateSolidBrush(GetSysColor(COLOR_BTNHIGHLIGHT)); cyChar = HIWORD(GetDialogBaseUnits());
注意,在hwndRect的创建风格时候使用SS_WHITERECT
在msdn上面的描述是这样的: Specifies a rectangle filled with the color used to fill the window background. The default is white.
说明使用默认的白色用来填充窗口背景色。并在WM_SIZE的时候将hwndRect充满整个窗口的左半部分,所以整个窗口的左半部分显示为白色。
这里通过拦截滚动条的默认窗口处理函数来进行对滚动条的一些特殊处理 OldScroll[i] = (WNDPROC)SetWindowLong(hwndScroll[i], GWL_WNDPROC, (LONG)ScrollProc);
case WM_CTLCOLORSCROLLBAR: return (LRESULT)hBrush[GetWindowLong((HWND)lParam, GWL_ID)]; case WM_CTLCOLORSTATIC: { int id = GetWindowLong((HWND)lParam,GWL_ID); if (id > 2 && id < 9) { SetTextColor((HDC)wParam, crPrim[id % 3]); SetBkColor((HDC)wParam, GetSysColor(COLOR_BTNHIGHLIGHT)); return (LRESULT)hBrushStatic; } } break;
在static和scrollbar类型的界面画刷拦截显示中,通过返回对应的画刷句柄实现对static文字背景颜色的填充。也可以有其他一些图像之类的填充。
以下是在WM_VSCROLL中执行的修改整个窗口背景画刷,并使整个窗口背景的右半部分无效,重新填充颜色
DeleteObject((HBRUSH)SetClassLong(hwnd,GCL_HBRBACKGROUND, (LONG)CreateSolidBrush(RGB(color[0],color[1],color[2]))));
InvalidateRect(hwnd,&rcColor,TRUE);
时间: 2024-10-17 02:43:16