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!
JoeBurwellAsked:
Who is Participating?
 
chensuConnect With a Mentor Commented:
Two methods:

1. Multithread

Look into my article at CodeGuru.
http://www.codeguru.com/internet/urlfile.shtml

2. PumpMessage

There is an article in MSJ.

0
 
JoeBurwellAuthor Commented:
Edited text of question.
0
 
chensuCommented:
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.
0
 
jkrCommented:
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()'


0
 
JoeBurwellAuthor Commented:
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!

0
All Courses

From novice to tech pro — start learning today.