Keep a CView from invalidating the clientspace on WM_SIZE

How do I keep my CView-derived class from invalidating the entire client space during WM_SIZE(OnSize)?  I have already tried defining a class without CS_HREDRAW and CS_VREDRAW by adding the following line in PreCreateWindow:


Who is Participating?
koskiaConnect With a Mentor Commented:
you can make another cool thing.
use a boolean variable to check if the window was resized
in the OnSize function set the boolean to true
in the overrrided of OnPaint() check if the redraw becomes from resizing the window, and act diferrently on both occasions (you decide which area to redraw and why).
you can actually do nothing, set the flag back to false, and
Invalidate the window with the rectangle you calculate,
ofcourse there won't be a loop because the boolean value will change.

class CMyView : public CView {
    BOOL m_bFromSize;
    CRect m_rPrevSize;

void CMyView::OnSize(...)
    m_bFromSize = TRUE;

void CMyView::OnPaint(...)
    if (m_bFromSize)
       //calculate Invalidation Rectangles
       // usually 2 edges
       m_bFromSize = FALSE;


Assuming you have a class derived from CView, simply override the OnSize function, and do whatever you like.
JeffBeardsleyAuthor Commented:
The problem is, by the time OnSize() is invoked, the framework has already invalidated the window (querying the update rectangle at this point yields the same results as querying the client rectangle).

I WANT only those areas of the window that have been exposed by the size event to be marked invalid.
Learn to develop an Android App

Want to increase your earning potential in 2018? Pad your resume with app building experience. Learn how with this hands-on course.

This works for me:

BOOL CMyView::PreCreateWindow(CREATESTRUCT& cs)
   static CString sClass = AfxRegisterWndClass(0);

   cs.lpszClass = sClass;
   return CView::PreCreateWindow(cs);

Find out whether any parent of the view's window has class-styles CS_HREDRAW | CS_VREDRAW (e.g. with Spy++). If so, you can also reset the styles using something like this after creating the window (where pWnd is the window) :

 GetClassLong( pWnd->m_hWnd, GCL_STYLE ) & ~( CS_HREDRAW | CS_VREDRAW )

hope that helps,

JeffBeardsleyAuthor Commented:
The original response answered the wrong question.  The best input actually came in the form of comments from piano_boxer and zoppo.
JeffBeardsleyAuthor Commented:
Adjusted points to 100
did you check if the invalidated area is already defined in OnSizing??
maybe you can change it there
JeffBeardsleyAuthor Commented:
I can see that that will work -- I had actually considered such a solution, but had assumed there would be a standard/accepted method of dealing with the problem.
I don't think there is a standard method of dealing with such a thing, anyway the aboved answer works, and the overhead seems very little
(unless you're dealing with realtime and animation, which every milli counts)
All Courses

From novice to tech pro — start learning today.