[Home] [Downloads] [Search] [Help/forum]

Gammon Forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Development
. . -> [Subject]  Redraw/Repaint code
Home  |  Users  |  Search  |  FAQ
Register forum user name
Forgotten password?

Redraw/Repaint code

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page

Posted by Fiendish   USA  (1,641 posts)  [Biography] bio   Global Moderator
Date Tue 30 Nov 2010 12:19 AM (UTC)

Amended on Tue 30 Nov 2010 12:21 AM (UTC) by Fiendish

I'm looking at methods_output.cpp, and there's something I'm not getting.

CMUSHclientDoc::Redraw() just calls UpdateAllViews(NULL).
CMUSHclientDoc::Repaint() does...
UpdateAllViews (NULL);
for(POSITION pos = GetFirstViewPosition(); pos != NULL; )
  CView* pView = GetNextView(pos);
  if (pView->IsKindOf(RUNTIME_CLASS(CMUSHView)))
     CMUSHView* pmyView = (CMUSHView*)pView;
     pmyView->UpdateWindow ();
  } // end of being a CMUSHView
} // end of loop through views
Which is oddly similar to a combination of Redraw() and this example code for CDocument::GetFirstViewPosition (MFC) from http://msdn.microsoft.com/en-us/library/ysfkkk2h%28VS.80%29.aspx
// This example uses CDocument::GetFirstViewPosition
// and GetNextView to repaint each view.
void CMyDoc::OnRepaintAllViews()
  POSITION pos = GetFirstViewPosition();
  while (pos != NULL)
    CView* pView = GetNextView(pos);

// An easier way to accomplish the same result is to call
// UpdateAllViews(NULL);
Notice that comment at the bottom. MSDN appears to be claiming that Repaint() is just like calling Redraw() twice, with the minor difference of your CMUSHView pointer shuffling (what is that for?).
Indeed, the example code for CDocument::UpdateAllViews (MFC) from http://msdn.microsoft.com/en-us/library/eys41xfw%28VS.80%29.aspx is
void CMyDoc::OnRepaintAllViews()
Which is the same function declaration as above. So what's going on here?

[Go to top] top

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] bio   Forum Administrator
Date Reply #1 on Tue 30 Nov 2010 12:40 AM (UTC)

Amended on Tue 30 Nov 2010 12:46 AM (UTC) by Nick Gammon

Never mind what the comments say. Look at the descriptions for the APIs.

(my emphasis below)

CDocument::UpdateAllViews calls CView::OnUpdate for each view.

CView::OnUpdate does this:

Called by the framework after the view's document has been modified; this function is called by CDocument::UpdateAllViews and allows the view to update its display to reflect those modifications. It is also called by the default implementation of OnInitialUpdate. The default implementation invalidates the entire client area, marking it for painting when the next WM_PAINT message is received.

So basically UpdateAllViews invalidates (marks for painting) all windows. However it doesn't actually draw them. That is done in the main message loop when Windows notices that there are views with invalidated regions, and then sends them a WM_PAINT message. (This causes the OnDraw function to be called to actually draw the window).

Meanwhile CWnd::UpdateWindow does this:

Updates the client area by sending a WM_PAINT message if the update region is not empty. The UpdateWindow member function sends a WM_PAINT message directly, bypassing the application queue. If the update region is empty, WM_PAINT is not sent.

So this sends the WM_PAINT message now rather than in the future. In my Repaint function I first call UpdateAllViews (NULL) in order to satisfy the condition that the update region is not empty.

To summarise:

  • Redraw invalidates but doesn't paint.

  • Repaint immediately paints.

Note that the documenation for WM_PAINT says:

The system sends this message when there are no other messages in the application's message queue.

DispatchMessage determines where to send the message; GetMessage determines which message to dispatch. GetMessage returns the WM_PAINT message when there are no other messages in the application's message queue, and DispatchMessage sends the message to the appropriate window procedure.

This makes invalidating the window effectively marking the painting as low priority. So if there is a queue of mouse-downs, key-presses, incoming network messages, etc. these are processed first.

The comment about "An easier way to accomplish the same result is to call UpdateAllViews(NULL);" is a bit misleading. It accomplishes a similar result, but a deferred result. It isn't the identical result.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page

Go to topic:           Search the forum

[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at FutureQuest]