0

I have a problem, When I move my child window over the main window it is being drawed on it during WM_PAINT and it looks like this: window (it disappears quickly). How can I fix this? Here is my code, 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;
}

And how I create my windows:

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);

It's funny, because when I move other window over my main window (eg. Google Chrome), everything is OK.

Community
  • 1
  • 1
Mikołaj
  • 93
  • 6
  • Did you forget for example Registering the windows: `RegisterClassEx(&wc)`? – Raindrop7 Feb 12 '17 at 12:55
  • I have it in the other part of my code, just forgot to paste it. – Mikołaj Feb 12 '17 at 13:05
  • So I think maybe you are registering the two windows with the same WINDOWCLASD 'wc'. – Raindrop7 Feb 12 '17 at 13:46
  • I think you are talking about the "ghost" of the window that might be visible for a bit when you move a window. The more typical artifact is a "trail". This happens when the overlapped window is slow to handle the WM_ERASEBKG message, it will then just take a while for the pixels to be overdrawn. No real cue from the snippet why this would be the case, other than that the WM_PAINT handler is not particularly fast and seems to draw the entire window. Rough guess is that the WM_ERASEBKG handler does nothing. Solved problem btw, Aero eliminates these artifacts, try not to get stuck on XP. – Hans Passant Feb 12 '17 at 14:03
  • This problem is only my friend's computer (win XP), I have everything OK (win 7+win10). So I won't fix it until I won't use additional libraries (Areo)? – Mikołaj Feb 12 '17 at 14:43
  • And why don't I have this problems with other windows, but only with one ("Log in" window)? – Mikołaj Feb 12 '17 at 14:53
  • Minor but important nitpick: this is not a *child* window; this is an *owned* window. That being said, we'll need to see your window procedures. – andlabs Feb 12 '17 at 17:12

0 Answers0