Solved

DoEvents in VC++/MFC

Posted on 2001-06-05
4
793 Views
Last Modified: 2008-03-10
Hello,

My problem is the following:

I have a loop that repeats a couple of instruction to generate a sound. I want to be able to stop this loop at one point. To be able to do that, I made a Global Variable (bool Stop). And each time i redo my loop i check it it's true, if it is I quit if not I loop.

In theory it's a good concept except that in practice my application freezes while it's in the loop and i can't seem to press my button that changes Stop (bool var) to true to end my loop.

I know that in VB, the DoEvents function gives you the possibility to do other actions (events ie keypress, mousepress) while in a loop. How do we do that in VC++.

Please provide code or links to ressource pages.

Any suggestions on different approach are welcome

Thanks again,

Luthar
0
Comment
Question by:luthar
  • 2
  • 2
4 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 50 total points
ID: 6157600
>>How do we do that in VC++.

You'll just have to dipatch the messages and 'drain' the message queue while the loop is running, e.g.

MSG msg;

while ( !bStop)
{

               while   (   PeekMessage (   &msg,   NULL,   0,  0,  PM_REMOVE))
                       {
                           DispatchMessage     (   &msg);
                       }

  // your loop code here
}


Feel free to ask if you need more information!
0
 

Author Comment

by:luthar
ID: 6157637
Thanks, everything works fine now.

Just one question, what's the specs of PeekMessage (in other words, what are the different parameters)?

&msg: obvious...
NULL:
0:
0:
PM_REMOVE:
0
 

Author Comment

by:luthar
ID: 6157642
Thanks, everything works fine now.

Just one question, what's the specs of PeekMessage (in other words, what are the different parameters)?

&msg: obvious...
NULL:
0:
0:
PM_REMOVE:
0
 
LVL 86

Expert Comment

by:jkr
ID: 6157778
Well, here's what the docs say (they're usually smarter than I am :o)

BOOL PeekMessage(
  LPMSG lpMsg,         // pointer to structure for message
  HWND hWnd,           // handle to window
  UINT wMsgFilterMin,  // first message
  UINT wMsgFilterMax,  // last message
  UINT wRemoveMsg      // removal flags
);
 
Parameters
lpMsg
Pointer to an MSG structure that receives message information.

hWnd
Handle to the window whose messages are to be examined.

(REMARK: In our case, if nothing is specified, it's the main message queue)
 
wMsgFilterMin
Specifies the value of the first message in the range of messages to be examined.

wMsgFilterMax
Specifies the value of the last message in the range of messages to be examined.

(REMARK: In our case, if nothing is specified, there is no filtering - but you could focus on e.g. mouse or keyboard messages)

wRemoveMsg
Specifies how messages are handled. This parameter can be one of the following values:
Value Meaning
PM_NOREMOVE Messages are not removed from the queue after processing by PeekMessage.
PM_REMOVE Messages are removed from the queue after processing by PeekMessage.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

863 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now