Link to home
Start Free TrialLog in
Avatar of JoeBurwell
JoeBurwell

asked on

Capturing Mouse Input to a modeless dialog box

In my application, selection of specific menu items causes the app to display two dialog boxes -- one for user selection of commands and one to display data.  In certain instances the user may wish to continuously retrieve data (activated by clicking on a button the "control" dialog box).  At this point the app must enter some type of loop that continuously retrieves the data (CDataRetrieve::OnRepeatRetrieve() ).  Once the app enters the loop the user must click on a "Stop Retrieve" button to cancel the continous data retrieval.  How can I program the app to stay in the loop while still:
a) allowing the user to left click on the "Stop Retrieve" button; and
b) ignoring any other messages (mouse movement, right click, keyboard entry, ...)

I don't need specific code examples unless it's the easiest way to describe the solution.  I just need to know the best way to implement this type of loop.
Thanks in advance!
Avatar of JoeBurwell
JoeBurwell

ASKER

Edited text of question.
ASKER CERTIFIED SOLUTION
Avatar of chensu
chensu
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Go to http://www.microsoft.com/msj to download the source code for Microsoft Systems Journal February 1997 Wicked Code. It implements a class called CWaitDialog.
Avatar of jkr
Simply add the following to the body of your loop:

MSG msg;

   if (GetMessage(&msg,0,0,0))
     {
       TranslateMessage(&msg);
       DispatchMessage(&msg);
     };

This will ensure that all messages are dispatched correctly during the execution of the loop - if you're only interested in a particular message range (as you mentioned, e.g. mouse messages, you might want to specify the range in the last 2 parameter of 'GetMessage()', e.g.

   if (GetMessage(&msg,0,WM_MOUSEFIRST,WM_MOUSELAST))

If you're interested in messages that 'belong' to your dialog, provide its handle as the 2nd parameter to 'GetMessage()'


Thanks for the quick response!
I started looking into the multithread possibility last night and just needed some reassurance.  The article listed at codeguru.com should have enough info for me to solve this particular problem.

Thanks again!