在我将 Visual Styles 设置为 on 后,公共控件没有用 WM_CTLCOLORSTATIC 处理程序正确绘制 [英] Common controls are not properly painted with WM_CTLCOLORSTATIC handler after I set Visual Styles on

查看:20
本文介绍了在我将 Visual Styles 设置为 on 后,公共控件没有用 WM_CTLCOLORSTATIC 处理程序正确绘制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

简介和相关信息:

我通过资源编辑器创建了 2 个对话框.由于我使用Microsoft Visual Studio Express 版,我不得不下载.要创建项目,请执行以下步骤:

1.) 在 Visual Studio 中创建默认的 Win32 项目.

2.) 在 stdafx.h 中复制/粘贴以下指令,在 #include 下方:

#include #include #pragma comment( 链接器, "/manifestdependency:\"type='win32' \name='Microsoft.Windows.Common-Controls' version='6.0.0.0' \处理器架构='*' publicKeyToken='6595b64144ccf1df' \语言='*'\"")#pragma 注释(lib,comctl32.lib")#pragma comment( lib,"Msimg32.lib")//GradientFill(...) API 需要#pragma comment( lib, "UxTheme.lib")

3.) 在资源编辑器中,通过添加 2 个 单选按钮、2 个 复选框 和一个 来更改 关于 对话框分组框将它们包围起来(参见上面的图片也明白我的意思)并添加一个treeview控件(该控件将触发"问题).

4.) 在主 cpp 文件中,添加用于绘制自定义背景的辅助函数:

void GradientTriangle( HDC MemDC,长 x1,长 y1,长 x2,长 y2,长 x3,长 y3,COLORREF 顶部,COLORREF 底部 ){TRIVERTEX 顶点[3];顶点[0].x = x1;顶点[0].y = y1;顶点[0].Red = GetRValue(底部)<<8;顶点[0].Green = GetGValue(底部)<<8;顶点[0].Blue = GetBValue(底部)<<8;顶点[0].Alpha = 0x0000;顶点[1].x = x3;顶点[1].y = y3;顶点[1].Red = GetRValue(底部)<<8;顶点 [1].Green = GetGValue(bottom) <<8;顶点[1].Blue = GetBValue(底部)<<8;顶点[1].Alpha = 0x0000;顶点[2].x = x2;顶点[2].y = y2;顶点[2].Red = GetRValue(top) <<8;顶点[2].Green = GetGValue(top)<<8;顶点[2].Blue = GetBValue(top)<<8;顶点[2].Alpha = 0x0000;//创建一个 GRADIENT_TRIANGLE 结构//引用 TRIVERTEX 顶点.GRADIENT_TRIANGLE gTriangle;gTriangle.Vertex1 = 0;gTriangle.Vertex2 = 1;gTriangle.Vertex3 = 2;//绘制一个阴影三角形.GradientFill(MemDC, vertex, 3, &gTriangle, 1, GRADIENT_FILL_TRIANGLE);}

5.) 在_tWinMain中启动common controls:

//初始化常用控件INITCOMMONCONTROLSEX iccex;iccex.dwSize = sizeof(INITCOMMONCONTROLSEX);iccex.dwICC = ICC_LISTVIEW_CLASSES |ICC_UPDOWN_CLASS |ICC_STANDARD_CLASSES ;InitCommonControlsEx(&iccex);

6.) 在 WM_INITDIALOGtreeview 中插入一些项目:

case WM_INITDIALOG:{HWND TreeView = GetDlgItem( hDlg, IDC_TREE1 );//添加根项TVINSERTSTRUCT tvis = {0};tvis.item.mask = TVIF_TEXT;tvis.item.pszText = L"这是根项目";tvis.hInsertAfter = TVI_LAST;tvis.hParent = TVI_ROOT;HTREEITEM hRootItem = reinterpret_cast( SendMessage( TreeView ,TVM_INSERTTEM, 0, reinterpret_cast<LPARAM>(&tvis)));//为 hTreeItem 添加第一个子项memset(&tvis, 0, sizeof(TVINSERTSTRUCT));tvis.item.mask = TVIF_TEXT;tvis.item.pszText = L"这是第一个子项目";tvis.hInsertAfter = TVI_LAST;tvis.hParent = hRootItem;HTREEITEM hTreeSubItem1 = reinterpret_cast( SendMessage( TreeView ,TVM_INSERTTEM, 0, reinterpret_cast<LPARAM>(&tvis)));//现在我们为 hRootItem 插入第二个子项memset(&tvis, 0, sizeof(TVINSERTSTRUCT));tvis.item.mask = TVIF_TEXT |TVIF_STATE;//添加额外的标志tvis.item.pszText = L"这是第二个子项目";tvis.hInsertAfter = TVI_LAST;tvis.hParent = hRootItem;HTREEITEM hTreeSubItem2 = reinterpret_cast( SendMessage( TreeView ,TVM_INSERTTEM, 0, reinterpret_cast<LPARAM>(&tvis)));}返回(INT_PTR)真;

7.) 绘制对话框的自定义背景:

case WM_ERASEBKGND:{矩形 r;GetClientRect( hDlg, &r );GradientTriangle((HDC)wParam, r.right, r.bottom - r.top,r.left, r.bottom - r.top,r.left, r.top,RGB( 0x0, 0x0, 0xFF ), RGB( 0xFF, 0xFF, 0x0 ) );GradientTriangle((HDC)wParam, r.right, r.bottom - r.top,r.right, r.top,r.left, r.top,RGB( 0xFF, 0x0, 0x0 ), RGB( 0x0, 0xFF, 0x0 ) );}返回真;

8.) 为 WM_CTLCOLORSTATIC 添加处理程序:

case WM_CTLCOLORSTATIC:if( ( (HWND)lParam == GetDlgItem( hDlg, IDC_RADIO1 ) )||((HWND)lParam == GetDlgItem(hDlg,IDC_CHECK1))){矩形 r;GetClientRect( hDlg, &r );DrawThemeParentBackground((HWND)lParam, (HDC)wParam, &r);}别的{SetTextColor( (HDC)wParam, RGB( 0, 0, 0 ) );SetBkMode((HDC)wParam, 透明);}返回(INT_PTR)((HBRUSH)GetStockObject(NULL_BRUSH));

这将是创建演示问题的最小程序所需的所有步骤和信息.现在运行应用程序并观察差异:

带有 IDC_RADIO1

单选按钮和带有 IDC_CHECK1checkbox 将被正确绘制(黑色透明文本),而其他 checkboxradio button 则不会.此外,在您单击 treeview 并按 spacebar 后,您将看到对话框背景的问题.

编辑结束

谢谢.

最好的问候.

解决方案

我已经制作了您的对话框并在 xp 和 7 中运行它,一切顺利.您应该做的是:

在内存中创建一个位图并在那里完成所有绘图.这应该是对话框背景.

HDC hdc = CreateIC(TEXT("DISPLAY"), NULL, NULL, NULL);hdcMemDialogBackground = CreateCompatibleDC(hdc);hBitmap = CreateCompatibleBitmap(hdc, dialogWidth, dialogHeight);hBitmapOld = SelectObject(hdcMemDialogBackground, hBitmap);删除DC(hdc);

要创建单选按钮和复选框,请使用非静态的按钮"类

WS_VISIBLE |WS_CHILD |BS_AUTOCHECKBOXWS_VISIBLE |WS_CHILD |BS_AUTORADIOBTON

样式.

在您的对话框中,您应该包括

WS_CLIPCHILDREN

风格.这将解决您按下空格键时背景与控件重叠的问题.

你不应该在WM_ERASEBKGND消息中绘制对话框的背景,而应该在WM_PAINT

case WM_PAINT:RECT r, rt;GetUpdateRect(hDlg, &rt, false);GetClientRect( hDlg, &r );GradientTriangle( hdcMemDialogBackground, r.right, r.bottom - r.top,r.left, r.bottom - r.top,r.left, r.top,RGB( 0x0, 0x0, 0xFF ), RGB( 0xFF, 0xFF, 0x0 ) );GradientTriangle( hdcMemDialogBackground, r.right, r.bottom - r.top,r.right, r.top,r.left, r.top,RGB( 0xFF, 0x0, 0x0 ), RGB( 0x0, 0xFF, 0x0 ) );hdc = BeginPaint(hDlg, &ps);BitBlt(hdc, rt.left, rt.top, rt.right - rt.left, rt.bottom - rt.top, hdcMemDialogBackground, rt.left, rt.top, SRCCOPY);EndPaint(hDlg, &ps);休息;

最后是透明背景,在WM_NOTIFY:

case WM_NOTIFY:NMHDR *核磁共振;NMCUSTOMDRAW *nmcd;nmr = (NMHDR *)lParam;nmcd = (NMCUSTOMDRAW *)lParam;if(nmr->idFrom == IDC_RADIO1 && nmr->code == NM_CUSTOMDRAW){如果(nmcd-> dwDrawStage == CDDS_PREERASE){BitBlt(nmcd-> hdc, 0, 0, radioButton1Width, radioButton1Height, hdcMemDialogBackground, radioButton1PosX, radioButton1PosY, SRCCOPY);返回 CDRF_SKIPDEFAULT;}}if(nmr->idFrom == IDC_RADIO2 && nmr->code == NM_CUSTOMDRAW){//相同}if(nmr->idFrom == IDC_CHECK1 && nmr->code == NM_CUSTOMDRAW){//相同}if(nmr->idFrom == IDC_CHECK2 && nmr->code == NM_CUSTOMDRAW){//相同}休息;

最后处置你的资源:

SelectObject(hdcMemDialogBackground, hBitmapOld);删除对象(hBitmap);hBitmap = NULL;DeleteDC(hdcMemDialogBackground);hdcMemDialogBackground = NULL;

编辑

POINT pt;RECT rt;GetClientRect(hwndRadioButton1, &rt);pt.x = 0;pt.y = 0;ClientToScreen(hwndRadioButton1, &pt);ScreenToClient(hDlg, &pt);BitBlt(nmcd-> hdc, 0, 0, rt.right, rt.bottom, hdcMemDialogBackground, pt.x, pt.y, SRCCOPY);

EDIT2(用于调整大小)

更改 WM_PAINT:

case WM_PAINT:GetUpdateRect(hDlg, &rt, false);hdc = BeginPaint(hDlg, &ps);BitBlt(hdc, rt.left, rt.top, rt.right - rt.left, rt.bottom - rt.top, hdcMemDialogBackground, rt.left, rt.top, SRCCOPY);EndPaint(hDlg, &ps);休息;

在 WM_SIZE 中:

case WM_SIZE:r.left = 0;r.top = 0;r.right = LOWORD(lParam);;r.bottom = HIWORD(lParam);GradientTriangle(hdcMemDialogBackground, r.right, r.bottom - r.top,r.left, r.bottom - r.top,r.left, r.top,RGB( 0x0, 0x0, 0xFF ), RGB( 0xFF, 0xFF, 0x0 ) );GradientTriangle(hdcMemDialogBackground, r.right, r.bottom - r.top,r.right, r.top,r.left, r.top,RGB( 0xFF, 0x0, 0x0 ), RGB( 0x0, 0xFF, 0x0 ) );InvalidateRect(hwndRadioButton1, NULL, false);InvalidateRect(hwndRadioButton2, NULL, false);InvalidateRect(hwndCheck11, NULL, false);InvalidateRect(hwndCheck2, NULL, false);InvalidateRect(hDlg, NULL, false);休息;

要调整大小,您需要创建 hdcMemDialogBackground 最大尺寸对话框将有例如 1280x1024 或 1680x1050 或任何其他.

就是这样.

瓦尔特

INTRODUCTION AND RELEVANT INFORMATION:

I have 2 dialog boxes created via Resource editor. Since I use Microsoft Visual Studio Express edition, I had to download free resource editor to create them. In my program, I have Visual Styles enabled like this:

#include <commctrl.h>

#pragma comment( lib, "comctl32.lib")

#pragma comment( linker, "/manifestdependency:\"type='win32' \
        name='Microsoft.Windows.Common-Controls' version='6.0.0.0' \
        processorArchitecture='*' publicKeyToken='6595b64144ccf1df' \
        language='*'\"")

As far as I know, check box, radio button, and group box get WM_CTLCOLORSTATIC message for painting their text.

This is what I have coded for the first and second dialog box:

case WM_CTLCOLORSTATIC:
    {
        SetBkMode( (HDC)wParam, TRANSPARENT );
        SetTextColor( (HDC)wParam, RGB( 0, 0, 0 ) );
        return (INT_PTR)( (HBRUSH)GetStockObject(NULL_BRUSH) );
    }

I want those controls to have transparent text background and black color of their text.

THE PROBLEM:

On Windows XP, here is the result image for first dialog:

Group box has blue text, and brown border, while check box has everything black. On Windows 7, after starting the same program, I get this:

Here, group box and check box have proper text color, yet background of the check box and the border of the group box are wrong. In my dialog box, I have static controls and they are painted properly both on Windows 7 and Windows XP.

WHAT HAVE I TRIED SO FAR:

I have browsed through SO archive, but haven't found anything I could use to modify my WM_CTLCOLORSTATIC handler.

I have found a workaround which removes Visual Styles from those controls, so it can achieve the desired result, but I need to keep the Visual Styles and make the background of the text transparent, thus this solution can not satisfy me.

After looking through Visual Styles reference and a little experimenting, I have found a workaround for radio button and check box ( but not for group box ) with the following code:

case WM_CTLCOLORSTATIC:
    if( (HWND)lParam == GetDlgItem( hwnd, IDC_RADIO1 ) ) 
    {
        RECT r;
        GetClientRect( hwnd, &r );
        DrawThemeParentBackground( (HWND)lParam, (HDC)wParam, &r );
    }
    else
    {
        SetTextColor( (HDC)wParam, RGB( 0, 0, 0 ) );
        SetBkMode( (HDC)wParam, TRANSPARENT );
    }
    return (INT_PTR)( (HBRUSH)GetStockObject(NULL_BRUSH) );

Still, I have "hit the wall" with this:

In my dialog box there is a treeview and once I select node and press spacebar ( or any other key for that matter ) dialog's background bitmap gets on top of my static controls.

After I comment out DrawThemeParentBackground(), recompile and start program again everything works fine ( when I select tree's node and press spacebar ) but then I am "at square one".

THE QUESTIONS:

  1. How can I modify my WM_CTLCOLORSTATIC handler to fix my problem ?

  2. If the above is not possible, can I get the desired effect with NM_CUSTOMDRAW ?

NOTE:

I think that I will have to draw group box using GDI. If that is the case, I will accept this solution too, as my main concern is checkbox and radio button.

EDITED WITH SUBMITTED EXAMPLE PROJECT:

On request, I am submitting a SSCCE. To create the project follow these steps:

1.) Create default Win32 project in Visual Studio.

2.) In the stdafx.h copy/paste the following directives, below #include <windows.h>:

#include <commctrl.h>
#include <Uxtheme.h>

#pragma comment( linker, "/manifestdependency:\"type='win32' \ 
                    name='Microsoft.Windows.Common-Controls' version='6.0.0.0' \
                    processorArchitecture='*' publicKeyToken='6595b64144ccf1df' \
                    language='*'\"")

#pragma comment( lib, "comctl32.lib")
#pragma comment( lib,"Msimg32.lib")    // needed for GradientFill(...) API
#pragma comment( lib, "UxTheme.lib")

3.) In the resource editor, alter About dialog box by adding a 2 radio buttons, 2 checkboxes and a group box enclosing them ( see the above pictures too see what I mean ) and add a treeview control ( this control will "trigger" the problem ).

4.) In your main cpp file, add the helper function for drawing the custom background:

void GradientTriangle( HDC MemDC, 
    LONG x1, LONG y1, 
    LONG x2, LONG y2, 
    LONG x3, LONG y3, 
    COLORREF top, COLORREF bottom )
{
    TRIVERTEX vertex[3];

    vertex[0].x     = x1;
    vertex[0].y     = y1;
    vertex[0].Red   = GetRValue(bottom) << 8;
    vertex[0].Green = GetGValue(bottom) << 8;
    vertex[0].Blue  = GetBValue(bottom) << 8;
    vertex[0].Alpha = 0x0000;

    vertex[1].x     = x3;
    vertex[1].y     = y3; 
    vertex[1].Red   = GetRValue(bottom) << 8;
    vertex[1].Green = GetGValue(bottom) << 8;
    vertex[1].Blue  = GetBValue(bottom) << 8;
    vertex[1].Alpha = 0x0000;

    vertex[2].x     = x2;
    vertex[2].y     = y2;
    vertex[2].Red   = GetRValue(top) << 8;
    vertex[2].Green = GetGValue(top) << 8;
    vertex[2].Blue  = GetBValue(top) << 8;
    vertex[2].Alpha = 0x0000;

    // Create a GRADIENT_TRIANGLE structure that
    // references the TRIVERTEX vertices.

    GRADIENT_TRIANGLE gTriangle;

    gTriangle.Vertex1 = 0;
    gTriangle.Vertex2 = 1;
    gTriangle.Vertex3 = 2;

    // Draw a shaded triangle.

    GradientFill( MemDC, vertex, 3, &gTriangle, 1, GRADIENT_FILL_TRIANGLE);
}

5.) Initiate common controls in _tWinMain:

// initialize common controls

INITCOMMONCONTROLSEX iccex;
iccex.dwSize = sizeof(INITCOMMONCONTROLSEX);
iccex.dwICC = ICC_LISTVIEW_CLASSES | ICC_UPDOWN_CLASS | ICC_STANDARD_CLASSES ;
InitCommonControlsEx(&iccex);

6.) Insert some items in the treeview in the WM_INITDIALOG :

case WM_INITDIALOG:
    {
        HWND TreeView = GetDlgItem( hDlg, IDC_TREE1 );

        // add root item

        TVINSERTSTRUCT tvis = {0};

        tvis.item.mask = TVIF_TEXT;
        tvis.item.pszText = L"This is root item";
        tvis.hInsertAfter = TVI_LAST;
        tvis.hParent = TVI_ROOT;

        HTREEITEM hRootItem = reinterpret_cast<HTREEITEM>( SendMessage( TreeView , 
            TVM_INSERTITEM, 0, reinterpret_cast<LPARAM>( &tvis ) ) );

        // add firts subitem for the hTreeItem

        memset( &tvis, 0, sizeof(TVINSERTSTRUCT) );

        tvis.item.mask = TVIF_TEXT;
        tvis.item.pszText = L"This is first subitem";
        tvis.hInsertAfter = TVI_LAST;
        tvis.hParent = hRootItem;

        HTREEITEM hTreeSubItem1 = reinterpret_cast<HTREEITEM>( SendMessage( TreeView , 
            TVM_INSERTITEM, 0, reinterpret_cast<LPARAM>( &tvis ) ) );

        // now we insert second subitem for hRootItem

        memset( &tvis, 0, sizeof(TVINSERTSTRUCT) );

        tvis.item.mask = TVIF_TEXT | TVIF_STATE; // added extra flag
        tvis.item.pszText = L"This is second subitem";
        tvis.hInsertAfter = TVI_LAST;
        tvis.hParent = hRootItem;

        HTREEITEM hTreeSubItem2 = reinterpret_cast<HTREEITEM>( SendMessage( TreeView , 
            TVM_INSERTITEM, 0, reinterpret_cast<LPARAM>( &tvis ) ) );
    }
    return (INT_PTR)TRUE;

7.) Paint the custom background of the dialog:

case WM_ERASEBKGND:
    {
        RECT r;
        GetClientRect( hDlg, &r );

        GradientTriangle( (HDC)wParam, r.right, r.bottom - r.top, 
            r.left, r.bottom - r.top,
            r.left, r.top,
            RGB( 0x0, 0x0, 0xFF ), RGB( 0xFF, 0xFF, 0x0 ) );

        GradientTriangle( (HDC)wParam, r.right, r.bottom - r.top, 
            r.right, r.top,
            r.left, r.top, 
            RGB( 0xFF, 0x0, 0x0 ), RGB( 0x0, 0xFF, 0x0 ) );
    }
    return TRUE;

8.) Add the handler for WM_CTLCOLORSTATIC:

case WM_CTLCOLORSTATIC:
    if( ( (HWND)lParam == GetDlgItem( hDlg, IDC_RADIO1 ) )       
        || ( (HWND)lParam == GetDlgItem( hDlg, IDC_CHECK1 ) ) ) 
    {
        RECT r;
        GetClientRect( hDlg, &r );
        DrawThemeParentBackground( (HWND)lParam, (HDC)wParam, &r );
    }
    else
    {
        SetTextColor( (HDC)wParam, RGB( 0, 0, 0 ) );
        SetBkMode( (HDC)wParam, TRANSPARENT );
    }
    return (INT_PTR)( (HBRUSH)GetStockObject(NULL_BRUSH) );

That would be all required steps and information to create minimal program that demonstrates the problem. Now run the application and observe the differences:

Radio button with IDC_RADIO1 and checkbox with IDC_CHECK1 will be properly painted ( transparent text with black color ), while other checkbox and radio button will not. Furthermore, after you click on a treeview and press spacebar you will see the problem with dialogs background.

END OF EDIT

Thank you.

Best regards.

解决方案

I have made your dialog and run it in both xp and 7 and everything went fine. What you should do is the following:

Create a bitmap in memory and do all your drawings there. This should be the dialog background.

HDC hdc = CreateIC(TEXT("DISPLAY"), NULL, NULL, NULL);
hdcMemDialogBackground = CreateCompatibleDC(hdc);
hBitmap = CreateCompatibleBitmap(hdc, dialogWidth, dialogHeight);
hBitmapOld = SelectObject(hdcMemDialogBackground , hBitmap);
DeleteDC(hdc);

For creating radiobutton and checkbox use "button" class not static with

WS_VISIBLE | WS_CHILD | BS_AUTOCHECKBOX
WS_VISIBLE | WS_CHILD | BS_AUTORADIOBUTTON

styles.

In your dialog you should include

WS_CLIPCHILDREN

style. This will solve you the background overlaping the controls upon space press.

You should not draw the background of dialog in WM_ERASEBKGND message but WM_PAINT

case WM_PAINT:
        RECT r, rt;
        GetUpdateRect(hDlg, &rt, false);

        GetClientRect( hDlg, &r );

        GradientTriangle( hdcMemDialogBackground, r.right, r.bottom - r.top, 
        r.left, r.bottom - r.top,
        r.left, r.top,
        RGB( 0x0, 0x0, 0xFF ), RGB( 0xFF, 0xFF, 0x0 ) );

        GradientTriangle( hdcMemDialogBackground, r.right, r.bottom - r.top, 
        r.right, r.top,
        r.left, r.top, 
        RGB( 0xFF, 0x0, 0x0 ), RGB( 0x0, 0xFF, 0x0 ) );

        hdc = BeginPaint(hDlg, &ps);

        BitBlt(hdc, rt.left, rt.top, rt.right - rt.left, rt.bottom - rt.top, hdcMemDialogBackground, rt.left, rt.top, SRCCOPY);

        EndPaint(hDlg, &ps);

        break;

And finaly for the transparent background, in WM_NOTIFY:

case WM_NOTIFY:
    NMHDR *nmr;
    NMCUSTOMDRAW *nmcd;

    nmr = (NMHDR *)lParam;
    nmcd = (NMCUSTOMDRAW *)lParam;

    if(nmr->idFrom == IDC_RADIO1 && nmr->code == NM_CUSTOMDRAW){
        if(nmcd->dwDrawStage == CDDS_PREERASE){
            BitBlt(nmcd->hdc, 0, 0, radioButton1Width, radioButton1Height, hdcMemDialogBackground, radioButton1PosX, radioButton1PosY, SRCCOPY);

            return CDRF_SKIPDEFAULT;
        }
    }

    if(nmr->idFrom == IDC_RADIO2 && nmr->code == NM_CUSTOMDRAW){
        //the same
    }

    if(nmr->idFrom == IDC_CHECK1 && nmr->code == NM_CUSTOMDRAW){
        //the same
    }

    if(nmr->idFrom == IDC_CHECK2 && nmr->code == NM_CUSTOMDRAW){
        //the same
    }

    break;

In the end dispose your resources:

SelectObject(hdcMemDialogBackground, hBitmapOld);
DeleteObject(hBitmap);
hBitmap = NULL;
DeleteDC(hdcMemDialogBackground);
hdcMemDialogBackground= NULL;

EDIT

POINT pt;
RECT rt;
GetClientRect(hwndRadioButton1, &rt);
pt.x = 0;
pt.y = 0;
ClientToScreen(hwndRadioButton1, &pt);
ScreenToClient(hDlg, &pt);

BitBlt(nmcd->hdc, 0, 0, rt.right, rt.bottom, hdcMemDialogBackground, pt.x, pt.y, SRCCOPY);

EDIT2 (for resizing)

Change WM_PAINT:

case WM_PAINT:
    GetUpdateRect(hDlg, &rt, false);
    hdc = BeginPaint(hDlg, &ps);

    BitBlt(hdc, rt.left, rt.top, rt.right - rt.left, rt.bottom - rt.top, hdcMemDialogBackground, rt.left, rt.top, SRCCOPY);

    EndPaint(hDlg, &ps);

    break;

In WM_SIZE:

case WM_SIZE:
    r.left = 0;
    r.top = 0;
    r.right = LOWORD(lParam);;
    r.bottom = HIWORD(lParam);

    GradientTriangle(hdcMemDialogBackground, r.right, r.bottom - r.top, 
                r.left, r.bottom - r.top,
                r.left, r.top,
                RGB( 0x0, 0x0, 0xFF ), RGB( 0xFF, 0xFF, 0x0 ) );

    GradientTriangle(hdcMemDialogBackground, r.right, r.bottom - r.top, 
                r.right, r.top,
                r.left, r.top, 
                RGB( 0xFF, 0x0, 0x0 ), RGB( 0x0, 0xFF, 0x0 ) );

    InvalidateRect(hwndRadioButton1, NULL, false);
    InvalidateRect(hwndRadioButton2, NULL, false);
    InvalidateRect(hwndCheck11, NULL, false);
    InvalidateRect(hwndCheck2, NULL, false);
    InvalidateRect(hDlg, NULL, false);

    break;

For the resizing to work you need to create hdcMemDialogBackground with the maximum dimensions dialogbox will have eg 1280x1024 or 1680x1050 or any other.

Thats it.

valter

这篇关于在我将 Visual Styles 设置为 on 后,公共控件没有用 WM_CTLCOLORSTATIC 处理程序正确绘制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆