PRB: InvalidateRect() Yields Empty Update Region on Win95

ID: Q180330


The information in this article applies to:


SYMPTOMS

The Win32 InvalidateRect() function, or the MFC function with the same name, does not invalidate any region on Microsoft Windows 95 or Windows 98, even though the function's return value is nonzero. A call to GetUpdateRect() afterwards returns a null rectangle, as well as a return value of zero. The same code works correctly on Microsoft Windows NT 4.0.


CAUSE

InvalidateRect(), or the MFC function that wraps it, behaves differently depending on whether you use it on Windows 95, Windows 98, or Windows NT 4.0. On Windows NT 4.0, InvalidateRect() will accept a pointer to a non- normalized RECT and invalidate a region as if the RECT were normalized. Windows 95 and Windows 98 require that the RECT be normalized to use it successfully with InvalidateRect().


RESOLUTION

You can normalize the RECT yourself, or use the MFC function CRect::NormalizeRect() on the RECT whose pointer you are passing to InvalidateRect(). To normalize a RECT, you must compare the top and bottom values, and swap them if the top is greater than the bottom. In addition, you must swap the left and right values if the left is greater than the right.


STATUS

Microsoft is researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available.


MORE INFORMATION

A non-normalized rectangle can often be produced unintentionally if you use mapping modes other than MM_TEXT. MM_HIENGLISH, MM_LOENGLISH, MM_HIMETRIC, MM_LOMETRIC, and MM_TWIPS cause the y-axis to have the reverse direction of that for the default mapping mode (MM_TEXT). This can result in non- normalized RECTs. In addition, you can set up the two "custom" mapping modes (MM_ISOTROPIC and MM_ANISOTROPIC) so that either the y-axis or x- axis, or both, are reversed from that in MM_TEXT. You can produce non- normalized RECTs by using functions such as LPtoDP or DPtoLP when using a mapping mode other than the default.

Please also note that InvalidateRect uses client area device coordinates, not logical coordinates. This is by design.

Additional query words: Invalid Update


Keywords          : kbMFC KbUIDesign kbVC kbVC500 kbVC600 
Version           : win95/98:5.0,6.0;winnt:5.0,6.0
Platform          : Win95 winnt Win98 
Issue type        : kbprb 

Last Reviewed: July 26, 1999