Solved

Keep a CView from invalidating the clientspace on WM_SIZE

Posted on 1998-12-16
10
390 Views
Last Modified: 2013-11-20
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:

cs.lpszClass=AfxRegisterWndClass(0);

Thanks
0
Comment
Question by:JeffBeardsley
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
10 Comments
 
LVL 2

Expert Comment

by:jstolan
ID: 1326270
Assuming you have a class derived from CView, simply override the OnSize function, and do whatever you like.
0
 

Author Comment

by:JeffBeardsley
ID: 1326271
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.
0
 
LVL 4

Expert Comment

by:piano_boxer
ID: 1326272
This works for me:

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

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

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 31

Expert Comment

by:Zoppo
ID: 1326273
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) :

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

hope that helps,

ZOPPO
0
 

Author Comment

by:JeffBeardsley
ID: 1326274
The original response answered the wrong question.  The best input actually came in the form of comments from piano_boxer and zoppo.
0
 

Author Comment

by:JeffBeardsley
ID: 1326275
Adjusted points to 100
0
 

Expert Comment

by:koskia
ID: 1326276
did you check if the invalidated area is already defined in OnSizing??
maybe you can change it there
0
 

Accepted Solution

by:
koskia earned 100 total points
ID: 1326277
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;
       InvalidateRect(horzRect);
       InvalidateRect(vertRect);
       return;
      }

      else
           OnDraw(...);
}
     


0
 

Author Comment

by:JeffBeardsley
ID: 1326278
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.
0
 

Expert Comment

by:koskia
ID: 1326279
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)
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
fizzArray  challenge 1 114
Window placement 17 99
Can not remove SSL certificate on iPhone 6 - iOS10.2 12 1,629
Increment column based of a FK 8 67
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question