C++ Win32选项卡控件灰色背景
我正试图在win32 everywhere中将我的ui设置为白色。问题是我的标签控件的背景不是白色的,所以标签不是标签本身,而是标签旁边的一方是灰色的 我正在为静态控件处理WM_CTLCOLORSTATIC,但它似乎不适用于选项卡控件C++ Win32选项卡控件灰色背景,c++,winapi,background,C++,Winapi,Background,我正试图在win32 everywhere中将我的ui设置为白色。问题是我的标签控件的背景不是白色的,所以标签不是标签本身,而是标签旁边的一方是灰色的 我正在为静态控件处理WM_CTLCOLORSTATIC,但它似乎不适用于选项卡控件 case WM_CTLCOLORSTATIC: { HDC hEdit = (HDC)w_param; SetBkMode(hEdit, TRANSPAREN
case WM_CTLCOLORSTATIC:
{
HDC hEdit = (HDC)w_param;
SetBkMode(hEdit, TRANSPARENT);
SetTextColor(hEdit, RGB(0, 0, 0));
SetBkColor(hEdit, RGB(255, 255, 255));
// Do not return a brush created by CreateSolidBrush(...) because you'll get a memory leak
return (INT_PTR)GetStockObject(WHITE_BRUSH);
}
我希望有一种“简单”的方法使我的整个ui变白:)
Grz您无法捕获要在灰色背景上绘制的消息。系统在
WM\u PRINTCLIENT
中绘制所有内容。然而,有一个很好的黑客!这个想法来自于
我这样做(在我的WM_绘制处理程序中):
TransparentBlt
:
创建hdcMemTab
,步骤1
在子类选项卡控件的WM_PAINT
中:
RECT rt, rtTab;
HDC hdc = BeginPaint(hwnd, &ps);
GetWindowRect(hwnd_Tab, &rt);
rt.right = rt.right - rt.left;
rt.bottom = rt.bottom - rt.top;
rt.left = 0;
rt.top = 0;
//step 2
SendMessage(hwnd_Tab, WM_PRINTCLIENT, (WPARAM)hdcMemTab, PRF_CLIENT);
FillRect(hdc, &rt, gBrushWhite); //gBrushWhite has the desired background color
HRGN hRgn = CreateRectRgn(0, 0, 0, 0);
int n_items = TabCtrl_GetItemCount(hwnd_Tab);
//get tabs region, step 3
for(i = 0; i < n_items; i++){
TabCtrl_GetItemRect(hwnd_Tab, i, &rtTab);
HRGN hTabRgn = CreateRectRgn(rtTab.left, rtTab.top, rtTab.right, rt.bottom);
CombineRgn(hRgn, hRgn, hTabRgn, RGN_OR);
DeleteObject(hTabRgn);
}
GetRgnBox(hRgn, &rtTab);
DeleteObject(hRgn);
//step 5
TransparentBlt(hdc, 0, 0, rt.right, rt.bottom, hdcMemTab, 0, 0, rt.right, rt.bottom, RGB(240, 240, 240)); //(240, 240, 240) is the grey color
BitBlt(hdc, rtTab.left, rtTab.top, rtTab.right - 5, rtTab.bottom, hdcMemTab, rtTab.left, rtTab.top, SRCCOPY);
EndPaint(hwnd, &ps);
//step 6
return 0;
RECT-rt,rtTab;
HDC HDC=开始喷漆(hwnd和ps);
GetWindowRect(hwnd_选项卡和rt);
rt.right=rt.right-rt.left;
rt.bottom=rt.bottom-rt.top;
rt.left=0;
rt.top=0;
//步骤2
SendMessage(hwnd_选项卡,WM_打印客户端,(WPARAM)hdcMemTab,PRF_客户端);
FillRect(hdc、rt和GBRUSH怀特)//gBrushWhite具有所需的背景色
HRGN HRGN=CreateRectRgn(0,0,0,0);
int n_items=TabCtrl_GetItemCount(hwnd_选项卡);
//获取选项卡区域,步骤3
对于(i=0;i对不起,我的英语不好。我要做的是在WM_PRINTCLIENT消息中返回0,而不执行任何操作,我的意思是,阻止WM_PRINTCLIENT调用DefWindowProc。这会导致tabcontrol标题与其父窗口具有相同的背景色。轨迹栏也是如此
我只在Windows10上测试过它,我想知道它是否也适用于Win7
RECT rt, rtTab;
HDC hdc = BeginPaint(hwnd, &ps);
GetWindowRect(hwnd_Tab, &rt);
rt.right = rt.right - rt.left;
rt.bottom = rt.bottom - rt.top;
rt.left = 0;
rt.top = 0;
//step 2
SendMessage(hwnd_Tab, WM_PRINTCLIENT, (WPARAM)hdcMemTab, PRF_CLIENT);
FillRect(hdc, &rt, gBrushWhite); //gBrushWhite has the desired background color
HRGN hRgn = CreateRectRgn(0, 0, 0, 0);
int n_items = TabCtrl_GetItemCount(hwnd_Tab);
//get tabs region, step 3
for(i = 0; i < n_items; i++){
TabCtrl_GetItemRect(hwnd_Tab, i, &rtTab);
HRGN hTabRgn = CreateRectRgn(rtTab.left, rtTab.top, rtTab.right, rt.bottom);
CombineRgn(hRgn, hRgn, hTabRgn, RGN_OR);
DeleteObject(hTabRgn);
}
GetRgnBox(hRgn, &rtTab);
DeleteObject(hRgn);
//step 5
TransparentBlt(hdc, 0, 0, rt.right, rt.bottom, hdcMemTab, 0, 0, rt.right, rt.bottom, RGB(240, 240, 240)); //(240, 240, 240) is the grey color
BitBlt(hdc, rtTab.left, rtTab.top, rtTab.right - 5, rtTab.bottom, hdcMemTab, rtTab.left, rtTab.top, SRCCOPY);
EndPaint(hwnd, &ps);
//step 6
return 0;