DrawThemeBackground()没有正确绘制选项卡

时间:2017-05-05 11:12:11

标签: c windows winapi

当我使用DrawThemeBackground()部分TABP_TABITEMRIGHTEDGE和状态TIRES_NORMAL时,它会在右侧未涂漆时留下2像素宽的矩形。部件TABP_TABITEMTABP_TABITEMLEFTEDGETABP_TABITEMBOTHEDGE不会发生这种情况。我该怎么做才能解决这个问题?

编辑:这只发生在Windows 10中,而不是发生在widnows xp中。我可以擦除整个背景,然后绘制标签,这将解决我的问题,我不会在Windows 10中看到任何闪烁,但它会在旧版本的Windows中闪烁,我不想那样,所以我擦除不包括选项卡占用区域的背景。在窗口10中,它在标签的右侧留下2个像素宽的黑色矩形。是否有一个主题函数,告诉你DrawThemeBackground()指定的矩形将由DrawThemeBackground()绘制多少?

#include <windows.h>
#include <uxtheme.h>
#include <vsstyle.h>
#include <vssym32.h>


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


LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{ 
    static HTHEME hTheme;
    static HBRUSH hbrBkg;

    switch(msg)
    {
    case WM_CREATE:
        hTheme = OpenThemeData(0, L"Tab");
        hbrBkg = CreateSolidBrush(RGB(0, 120, 120));
        break;

    case WM_PAINT:
        {
            HDC hdc;
            PAINTSTRUCT ps;
            hdc = BeginPaint(hwnd, &ps);
            if(hdc)
            {
                HBRUSH hbr = CreateSolidBrush(RGB(255, 0, 0));
                if(hbrBkg) FillRect(hdc, &ps.rcPaint, hbrBkg);
                if(hbr)
                {
                    RECT rc = { 4, 4, 104, 44 };
                    FillRect(hdc, &rc, hbr);
                    if(hTheme) DrawThemeBackground(hTheme, hdc, TABP_TABITEMRIGHTEDGE, TIRES_NORMAL, &rc, 0);
                    DeleteObject(hbr);
                }
                EndPaint(hwnd, &ps);
            }
        }
        break;

    case WM_DESTROY:
        if(hTheme) CloseThemeData(hTheme);
        if(hbrBkg) DeleteObject(hbrBkg);
        PostQuitMessage(0);
        break;

    default:
        return DefWindowProcW(hwnd, msg, wParam, lParam);
    }

    return 0;
}


int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nCmdShow)
{ 
    const WCHAR szClassName[] = L"Themes";
    WNDCLASSEXW wc;
    HWND hwnd;
    MSG msg;


    SecureZeroMemory(&wc, sizeof(WNDCLASSEXW));
    wc.cbSize        = sizeof(WNDCLASSEXW);
    wc.hCursor       = LoadCursorW(0, IDC_ARROW);
    wc.hIcon         = LoadIconW(0, IDI_APPLICATION);;
    wc.hInstance     = hInstance;
    wc.lpfnWndProc   = WndProc;
    wc.lpszClassName = szClassName;
    if(!RegisterClassExW(&wc)) return 0;


    hwnd = CreateWindowExW(0, szClassName, L"Test", WS_OVERLAPPEDWINDOW, 140, 140, 440, 240, 0, 0, hInstance, 0); 
    if(!hwnd) return 0;


    ShowWindow(hwnd, nCmdShow);
    UpdateWindow(hwnd);


    while(GetMessageW(&msg, 0, 0, 0) > 0)
    {
        if(!IsDialogMessageW(hwnd, &msg))
        {
            TranslateMessage(&msg); 
            DispatchMessageW(&msg);
        }
    }

    return (int)msg.wParam;
}

enter image description here

0 个答案:

没有答案
相关问题