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

1. Multithread

Look into my article at CodeGuru.

2. PumpMessage

There is an article in MSJ.

JoeBurwellAuthor Commented:
Edited text of question.
Go to to download the source code for Microsoft Systems Journal February 1997 Wicked Code. It implements a class called CWaitDialog.
Simply add the following to the body of your loop:

MSG msg;

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

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()'

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 should have enough info for me to solve this particular problem.

Thanks again!

All Courses

From novice to tech pro — start learning today.