Solved

DoEvents in VC++/MFC

Posted on 2001-06-05
4
791 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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

743 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

13 Experts available now in Live!

Get 1:1 Help Now