سؤال

In reference to Windows GDI, what is the difference between an invalid and valid region? I understand that a call to InvalidateRect() sends a WM_PAINT message to the queue, but what exactly is an "invalid" region?

هل كانت مفيدة؟

المحلول 2

The windowing system generally tries to avoid redrawing anything unless necessary, e.g. because something has changed, or another window has moved across it. When this happens, it marks the region as invalid to say that it needs to be redrawn. Alternatively, a region/window can be manually invalidated to force a redraw.

When the application responds to the WM_PAINT message, it will try to be as efficient as possible by only redrawing in the invalidated area. When it's finished, it marks it as valid to indicate that it's now up-to-date.

This selective redraw approach isn't as important today as it used to be. In the past, the drawing operations were much slower, so optimisation was absolutely essential.

نصائح أخرى

I understand that a call to InvalidateRect() sends a WM_PAINT message to the queue.

Well, not exactly. When you call InvalidateRect, you mark that rectangular region as being invalid and needing to be repainted. But no messages are sent. In fact, no message is even posted to the queue.

When you call GetMessage, or one of its equivalents, if the queue is empty, and there are windows in the thread that have dirty regions, then the system synthesises a WM_PAINT message. This synthesised WM_PAINT message is returned from GetMessage. The window's handler for WM_PAINT should then paint the window and thus make it valid again.

So, an invalid region is one that is pending painting. You have told the system that you want that region to be re-painted, and the system will arrange for that to happen once the higher priority queued messages have been processed.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top