开发者

Windows 7 sends unnecessary WM_PAINT messages

开发者 https://www.devze.com 2023-02-25 20:35 出处:网络
I have a question about strangely originating WM_PAINT messages sent to my window. 开发者_JAVA百科It happens on Windows 7 and doesn’t happen on Windows XP.

I have a question about strangely originating WM_PAINT messages sent to my window. 开发者_JAVA百科It happens on Windows 7 and doesn’t happen on Windows XP.

Details

In my program, I have a timer that triggers GUI updates, the timer is based on this API call:

CreateTimerQueueTimer

In the thread provided my the system to process timer expiration, I do some GUI updates, namely, drawing a line in the window (0,0)->(57,50):

HDC hdc = GetDC (hwnd);
MoveToEx (hdc, 0, 0, NULL);
LineTo (hdc, 57, 50);
ReleaseDC(hwnd,hdc);

In works as I would expect on Windows XP, but on Windows7 this makes a system to send WM_PAINT message to this window with update region: (0,0,58,51). Notice that rectangle is by one pixel wider than the square area affected by the line.

This WM_PAINT arriving because of this drawing is something that I don’t understand. The window is not touched/overlapped/resized or whatever. Apparently, this line is recognized by the system as invalidation of the rectangle.

And this only happens when in Windows 7 (as opposed to Windows XP).

Question

Is it something new about WDM or windows handling in W7? Any way to avoid this?

It maybe a bug in my program or the graphic toolkit I’m using (or both). But why it only manifests on Windows 7 then?

Thanks for any clue!

Denny


Psychic debugging time (in other words, I'm totally guessing)...

Remember that you can only update the content of a window from the thread which created the window. If you're calling GetDC()..ReleaseDC() from a thread other than the thread which created the window, I'm not suprised it's causing problems.

The timer APIs for Vista/Win7 have a totally different implementation from the timer APIs in XP, it's entirely possible that your timer might be running on a different thread.

Instead of drawing in the timer, why not post a message to the window indicating that the timer fired. Then in the message handler, invalidate the region for the window. Then handle drawing the line in the WM_PAINT handler.

In general Windows is much happier if you paint on a window in the WM_PAINT handler instead of painting during other window messages.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号