在WM_PAINT期间,在主窗口上绘制儿童窗口

时间:2017-02-12 12:37:36

标签: c++ winapi window gdi+ wm-paint

我有问题, 当我将子窗口移动到主窗口上时,它在WM_PAINT期间被绘制在它上面,它看起来像这样: window (它快速消失)。 我怎样才能解决这个问题?这是我的代码,WM_PAINT:

case WM_PAINT:
{
    PAINTSTRUCT ps = { 0 };
    HDC hdc = BeginPaint(hwnd, &ps);
    RECT rc;
    GetClientRect(hwnd, &rc);
    HDC memdc = CreateCompatibleDC(hdc);
    HBITMAP hbitmap = CreateCompatibleBitmap(hdc, rc.right, rc.bottom);
    HGDIOBJ oldbmp = SelectObject(memdc, hbitmap);

    FillRect(memdc, &rc, WHITE_BRUSH);
    Gdiplus::Graphics gr(memdc);
    gr.DrawImage(firstImage, 0, 150, 810, 400);
    gr.DrawImage(secondImage, 0, 0, 800, 580);

    BitBlt(hdc, 0, 0, rc.right, rc.bottom, memdc, 0, 0, SRCCOPY);

    SelectObject(memdc, oldbmp);
    DeleteObject(hbitmap);
    DeleteDC(memdc);

    EndPaint(hwnd, &ps);

    return 0;
}

我如何创建我的窗口:

memset(&wc, 0, sizeof(wc));

wc.style         = CS_HREDRAW | CS_VREDRAW;
wc.cbSize        = sizeof(WNDCLASSEX);
wc.lpfnWndProc   = WndProc;
wc.hInstance     = hInstance;
wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wc.lpszClassName = "WindowClass";
wc.hIcon         = LoadIcon(NULL, IDI_APPLICATION);
wc.hIconSm       = LoadIcon(NULL, IDI_APPLICATION);
wc.hIcon         = LoadIcon( GetModuleHandle( NULL ), MAKEINTRESOURCE( 1284 ) );
wc.hIconSm       = LoadIcon( GetModuleHandle( NULL ), MAKEINTRESOURCE( 2503 ) );

INITCOMMONCONTROLSEX iccex;
iccex.dwICC = ICC_WIN95_CLASSES;
iccex.dwSize = sizeof( INITCOMMONCONTROLSEX );
InitCommonControlsEx( & iccex );

hwnd = CreateWindowEx(WS_EX_CLIENTEDGE,"WindowClass","Launcher",WS_VISIBLE | WS_SYSMENU | WS_MINIMIZEBOX | WS_CLIPCHILDREN,
    CW_USEDEFAULT, /* x */
    CW_USEDEFAULT, /* y */
    500, /* width */
    120, /* height */
    NULL,NULL,hInstance,NULL);

memset(&wc,0,sizeof(wc));

wc.cbSize        = sizeof(WNDCLASSEX);
wc.lpfnWndProc   = WndProc2;
wc.hInstance     = hInstance;
wc.hCursor       = LoadCursor(NULL, IDC_ARROW); 
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wc.lpszClassName = "WindowClass2";
wc.hIcon         = LoadIcon(NULL, IDI_APPLICATION);
wc.hIconSm       = LoadIcon(NULL, IDI_APPLICATION);
wc.hIcon         = LoadIcon( GetModuleHandle( NULL ), MAKEINTRESOURCE( 1284 ) );
wc.hIconSm       = LoadIcon( GetModuleHandle( NULL ), MAKEINTRESOURCE( 2503 ) );

hwndLog = CreateWindowEx(WS_EX_CLIENTEDGE,"WindowClass2", "Log in",WS_DLGFRAME|WS_EX_TOOLWINDOW|WS_EX_TOPMOST|WS_SYSMENU|WS_CAPTION,
    CW_USEDEFAULT, /* x */
    CW_USEDEFAULT, /* y */
    600, /* width */
    200, /* height */
    hwnd,NULL,hInstance,NULL);

这很有趣,因为当我在主窗口(例如Google Chrome)上移动其他窗口时,一切正常。

0 个答案:

没有答案