Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to update one region of the view...

Posted on 2004-08-16
10
Medium Priority
?
387 Views
Last Modified: 2013-11-20
I've got a large, double-buffered, scrollable view in an SDI app.  When the user clicks in the view, the corresponding value in the document is toggled, and the the view needs to be updated to show the change.

Currently I just Invalidate() the view and cause it to be redrawn, but it's big enough that it's just too slow to redraw the whole thing every time the user interacts with it.  I am trying to figure out how to update just a small region of the view.  I would like to be able to update a region without going through all the nested loops of the OnDraw() function (I know that you can use clipping regions so that OnDraw() only updates a specific region, it would still take too long to go through everything I have in there).

Thanks for your help, experts!
0
Comment
Question by:idlegravity
[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 45

Accepted Solution

by:
AndyAinscow earned 252 total points
ID: 11817866
This function should be what you require.
Find out what needs to be repainted AND what part of that is visible.  Then redraw that part.


CWnd::GetUpdateRect
BOOL GetUpdateRect( LPRECT lpRect, BOOL bErase = FALSE );

Return Value

Specifies the status of the update region. The value is nonzero if the update region is not empty; otherwise 0.

If the lpRect parameter is set to NULL, the return value is nonzero if an update region exists; otherwise 0.

Parameters

lpRect

Points to a CRect object or RECT structure that is to receive the client coordinates of the update that encloses the update region.

Set this parameter to NULL to determine whether an update region exists within the CWnd. If lpRect is NULL, the GetUpdateRect member function returns nonzero if an update region exists and 0 if one does not. This provides a way to determine whether a WM_PAINT message resulted from an invalid area. Do not set this parameter to NULL in Windows version 3.0 and earlier.

bErase

Specifies whether the background in the update region is to be erased.

Remarks

Retrieves the coordinates of the smallest rectangle that completely encloses the update region. If CWnd was created with the CS_OWNDC style and the mapping mode is not MM_TEXT, the GetUpdateRect member function gives the rectangle in logical coordinates. Otherwise, GetUpdateRect gives the rectangle in client coordinates. If there is no update region, GetUpdateRect sets the rectangle to be empty (sets all coordinates to 0).

The bErase parameter specifies whether GetUpdateRect should erase the background of the update region. If bErase is TRUE and the update region is not empty, the background is erased. To erase the background, GetUpdateRect sends the WM_ERASEBKGND message.

The update rectangle retrieved by the BeginPaint member function is identical to that retrieved by the GetUpdateRect member function.

The BeginPaint member function automatically validates the update region, so any call to GetUpdateRect made immediately after a call to BeginPaint retrieves an empty update region.

0
 
LVL 5

Assisted Solution

by:Nass89
Nass89 earned 248 total points
ID: 11827495
Hi,
Have a look at:

from MSDN:

CWindow::InvalidateRect
BOOL InvalidateRect( LPCRECT lpRect, BOOL bErase = TRUE );

SeeInvalidateRect in the Win32 SDK.

Remarks

Invalidates the client area within the specified rectangle.


Good Luck!
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 11828355
If the information you present has a tabular format, then CListView in "Report mode" derived window will be more suitable for your needs, because it allows you to update row by row using owner draw feature, and of course has scrollbar.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 39

Expert Comment

by:itsmeandnobodyelse
ID: 11833339
GetUpdateRect only receives the enclosing update rectangle of the update region that is determined by one or more calls to InvalidateRect.

Therefore, use InvalidateRect as Nass98 told you and the next painting happens automatically ...

(from MSDN)

Windows sends a WM_PAINT message whenever the CWnd update region is not empty and there are no other messages in the application queue for that window.

Regards, Alex

0
 
LVL 45

Expert Comment

by:AndyAinscow
ID: 11833899
? - without using GetUpdateRect how does idlegravity know what to repaint, as he says it is too big to repaint the complete view (as he presumable does at present) and since when does windows draw the contents of your view.
0
 
LVL 39

Expert Comment

by:itsmeandnobodyelse
ID: 11838419
>>  without using GetUpdateRect how does idlegravity know what to repaint

Look to your post above:

   The update rectangle retrieved by the BeginPaint member function is identical to that retrieved
    by the GetUpdateRect member function.

   The BeginPaint member function automatically validates the update region, so any call to
   GetUpdateRect made immediately after a call to BeginPaint retrieves an empty update region.

So InvalidateRect is first (you have to say what regions became invalid) and BeginPaint gets the rectangle to update. You could call GetUpdateRect if you are actively drawing but not in OnDraw as you would get an empty rectangle. Furthermore, if you already have to know the update rectangle before calling InvalidateRect, there is no need to retrieve that rectangle again, except there are more than one regions to update.

Regards, Alex

0
 
LVL 45

Expert Comment

by:AndyAinscow
ID: 11838693
void CMyView::OnPaint()
{
      GetUpdateRect(&m_rectUpdate);
      CPaintDC dc(this); // device context for painting
      OnDraw(&dc);
}


m_rectUpdate contains the rectangle to redraw
0
 
LVL 45

Expert Comment

by:AndyAinscow
ID: 11838868
this is actually better

void CMyView::OnPaint()
{
     GetUpdateRect(&m_rectUpdate);
     CScrollView::OnPaint();  //or whatever your base class is
}


m_rectUpdate contains the rectangle to redraw
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
Ready to get certified? Check out some courses that help you prepare for third-party exams.
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.
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

609 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