工程师我用BS_OWNERDRAW样式创建了3个按钮现在如何刷
函数WndProc(Hwnd,message,wparam,lparam)CASE WM_CTLCOLORBTN if wparam = Button1然后WndProc = hBrushbtn1Elseif Wparam = Button2然后WndProc = hBrushbt 2结束如果必须获得Wparam的Lparam以及如何?
我无法获得每个按钮的刷柄
当所有者绘制的按钮想要更改其颜色时,在父窗口中处理WM_DRAWITEM消息。
使用BS_OWNERDRAW style创建所有者绘制的按钮:
hwndButton1 = CreateWindowW(L"BUTTON", NULL,
WS_CHILD | WS_VISIBLE | BS_OWNERDRAW,
10, 10, 100, 100,
hWnd, NULL, (HINSTANCE)GetWindowLong(hWnd, GWL_HINSTANCE), NULL);
在按钮的父窗口的Window过程中:
case WM_DRAWITEM:
{
LPDRAWITEMSTRUCT lpDIS = (LPDRAWITEMSTRUCT)lParam;
if (hwndButton1 == lpDIS->hwndItem)
{
SetDCBrushColor(lpDIS->hDC, RGB(255, 0, 0));
SelectObject(lpDIS->hDC, GetStockObject(DC_BRUSH));
RoundRect(lpDIS->hDC, lpDIS->rcItem.left, lpDIS->rcItem.top,
lpDIS->rcItem.right, lpDIS->rcItem.bottom, 5, 5);
return TRUE;
}
}
break;