[英]Why when I paint, and the mouse is moving in the window, the painting is not done at the same time everywhere? (WinAPI)
在問了這個問題之后,我改變了我的代碼。 它有效,但是當 WM_PAINT 繪制 window 並且 cursor 在其中移動時,繪制並不是同時在所有地方完成的。 在這里你有一個視頻可以更好地看到它。 這是我的 WM_PAINT:
//TV is a struct with the dimensions of the window.
//BitmapBuffer is the bitmap containing the painting.
static int cont;
cont++;
HDC HDc;
PAINTSTRUCT ps;
HDc = BeginPaint(identifier, &ps);
Gdiplus::Graphics lienzo (HDc);
AlphaBlend(HDc, 0, 0, TV.width+4, TV.height+4, buffer, 0, 0, TV.width+4, TV.height+4, CopyInfo);
EndPaint(identifier, &ps);
由於問題出在移動鼠標時,可能 WM_NCHITTEST 消息與此有關:
case WM_NCHITTEST:
POINTS point1 = MAKEPOINTS(lParam);
POINT point2;
point2.x = point1.x;
point2.y = point1.y;
ScreenToClient(hwnd, &point2);
if (PtInRegion(region, point2.x, point2.y))
{
if (inWindow == false) //inWindow is true when the cursor is in the window
{
inWindow = true;
TrackMouseEvent(&structure);
Repaint(); //this function repaint the buffer and after call invalidrect
}
return HTCLIENT;
}
else
{
if (inWindow == true)
{
inWindow = false;
Repaint();
}
return HTTRANSPARENT;
}
break;
有誰知道為什么會這樣?
讓你嘗試使用 WM_MOUSEMOVE 事件。
很難看出問題所在,因為您的代碼沒有定義 Repaint。 但是,您應該使用InvalidateRect告訴 Windows 哪個區域正在更新。
也就是說... Windows 很難在不使用雙緩沖技術的情況下進行編程以更新圖像。 這是當您繪制到 memory(位圖)然后將 bitmap 位映射到屏幕時。
您發現此答案很有用 使用 GDI+ 和 C++ 減少閃爍
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.