-
March 22nd, 2018, 12:50 AM
#1
on events
what is the difference between (i) and (ii):
(i)
void DoEvents()
{
MSG msg;
while(::PeekMessage(&msg, NULL, NULL, NULL, PM_NOREMOVE))
{
if (!AfxGetApp()->PumpMessage())
return;
}
}
(ii)
void DoEvents()
{
MSG msg;
while (::GetMessage(&msg, NULL, NULL, NULL))
{
if (!PreTranslateMessage(&msg))
{
::TranslateMessage(&msg);
:ispatchMessage(&msg);
}
}
}
-
March 22nd, 2018, 02:26 AM
#2
Re: on events
Well, trying to read/understand the basics from MSDN would be a good start!
Victor Nijegorodov
-
March 23rd, 2018, 05:29 AM
#3
Re: on events
thanks for the link, however, I needed more information on AfxGetApp()->PumpMessage(). I got more understanding about it by looking at some example codes and the code comments. MSDN does not seem to have much info on AfxGetApp()->PumpMessage().??
Thanks.
-
March 25th, 2018, 04:45 PM
#4
-
April 2nd, 2018, 03:02 AM
#5
Re: on events
Completing what already is answered above:
CWinThread::PumpMessage is documented in MSDN. Note that AfxGetApp gets a pointer to the application object which is of a class derived from CWinApp and CWinApp is derived from CWinThread.
Generally, you don't need to directly call PumpMessage in your MFC application.
If you want to see how CWinThread::PumpMessage is implemented, you can have a look in MFC framework source code.
Search it in <Visual Studio install folder>\VC\atlmfc\src\mfc or run your application in DEBUG mode then step into. See also Visual Studio 2015: How to Step into MFC Framework Code.
-
April 3rd, 2018, 11:53 AM
#6
Re: on events
Originally Posted by Y$EA
what is the difference between (i) and (ii):
The main difference is between PeekMessage(PM_NOREMOVE) and GetMessage(). PeekMessage() just peeks into message queue and lets you quit when the queue is empty. GetMessage() does not return until a message appears in the queue, so you have no chance to quit the DoEvents() function until the very moment of application shutdown.
Making long story short: GetMessage() blocks the thread, and PeekMessage() does not. Using DoEvents() based on PeekMessage() you may interleave your worker thread processing with pumping message queue. Otherwise you have to run your non-GUI stuff (typically something to do with heavy calculation or blocking communication) in a separate thread.
To understand the picture in whole you need to read MSDN regarding all the functions mentioned in the two snippets.
Last edited by Igor Vartanov; April 3rd, 2018 at 12:03 PM.
Best regards,
Igor
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|