繁体   English   中英

win32-gdi系统驱动的WM_PAINT无闪烁吗?

[英]Is win32-gdi system-driven WM_PAINT flicker free?

运行此代码会导致标题问题:

如果您调整 window 的大小,您将看不到任何闪烁(系统发送的重绘)

如果在 window 内移动鼠标,会出现严重的闪烁(我发送的重绘)

如何重现系统驱动的 WM_PAINT?

#include <windows.h>
#include <wingdi.h>

LRESULT CALLBACK proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
{
    switch(msg)
    {
        case WM_ERASEBKGND: return true;break;
        case WM_MOUSEMOVE: InvalidateRect(hwnd, 0, 0); break;
        case WM_PAINT:
        {
            InvalidateRect(hwnd,0,0);
            HBRUSH b= CreateSolidBrush(0x000000ff);
            HBRUSH c= CreateSolidBrush(0x0000ff00);
            HBRUSH d= CreateSolidBrush(0x00ff0000);
            RECT r;
            GetClientRect(hwnd,&r);
            PAINTSTRUCT ps;
            HDC hdc=BeginPaint(hwnd,&ps);
            FillRect(hdc,&r, b); 
            Sleep(10);
            FillRect(hdc,&r, c);
`           Sleep(10);
            FillRect(hdc,&r,d);
            EndPaint(hwnd,&ps);
            DeleteObject(b);
            DeleteObject(c);
            DeleteObject(d);
        }
        break;
        default:
            return DefWindowProc(hwnd, msg, wparam, lparam);
    }
    return 0;
}
int main()
{
    HWND hwnd=CreateWindow(WC_DIALOG,0,WS_OVERLAPPEDWINDOW|WS_VISIBLE,0,0,500,500,0,0,0,0);
    SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR)proc);
    
    MSG msg;
    
    while (true)
    {
        if (GetMessage(&msg, 0, 0, 0) != WM_CLOSE)
        {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
    }
    return 1;
}

如果鼠标只在 window 上移动,则不应使其无效,因为这最终会导致 WM_PAINT 消息。 这会导致闪烁(与睡眠相结合)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM