Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/137.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ Win32选项卡控件灰色背景_C++_Winapi_Background - Fatal编程技术网

C++ Win32选项卡控件灰色背景

C++ Win32选项卡控件灰色背景,c++,winapi,background,C++,Winapi,Background,我正试图在win32 everywhere中将我的ui设置为白色。问题是我的标签控件的背景不是白色的,所以标签不是标签本身,而是标签旁边的一方是灰色的 我正在为静态控件处理WM_CTLCOLORSTATIC,但它似乎不适用于选项卡控件 case WM_CTLCOLORSTATIC: { HDC hEdit = (HDC)w_param; SetBkMode(hEdit, TRANSPAREN

我正试图在win32 everywhere中将我的ui设置为白色。问题是我的标签控件的背景不是白色的,所以标签不是标签本身,而是标签旁边的一方是灰色的

我正在为静态控件处理WM_CTLCOLORSTATIC,但它似乎不适用于选项卡控件

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_绘制处理程序中):

  • 创建要绘制到的内存DC

  • 将WM_PRINTCLIENT消息发送到tab控件,使其将选项卡绘制到内存DC中

  • 创建一个镜像选项卡形状的区域

  • 用所需的背景笔刷填充该区域(RGN_DIFF)之外的内存DC部分

  • 将结果Blt到BeginPaint返回的DC中

  • 调用EndPaint并返回,当然不调用选项卡控件自己的WndProc:)

  • 步骤3有点复杂,因为您必须知道选项卡的位置和形状,但其他 除此之外,它是一个非常干净的解决方案(请参见下面的示例代码下图)。你 可能会使用TransparentBlt代替系统背景色

    我在此解决方案中使用的是
    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;