[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

DoEvents in VC++/MFC

Posted on 2001-06-05
4
Medium Priority
?
824 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 200 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

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.

Question has a verified solution.

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

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
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 be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
Suggested Courses

834 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