Solved

Accessing buttons while another process is running

Posted on 2003-10-28
2
169 Views
Last Modified: 2013-11-20
I have a program which calls for an infinte loop to fun and display output.  I need to be able to stop the program when the user clicks on a stop button.  The problem is while in the loop, the buttons appear to be inaccessable.  I would like to know how to make them clickable.

Thanks!
0
Comment
Question by:Logick
2 Comments
 
LVL 49

Accepted Solution

by:
DanRollins earned 125 total points
ID: 9638425
Add this function to your code:

void PumpMessagesForUI()
{
      MSG msg;
      while ( ::PeekMessage( &msg, NULL, 0, 0, PM_NOREMOVE ) )  {
            AfxGetApp()->PumpMessage();
      }
}

Create a global variable or on that is otherwise accessible from the onclick handler:

        BOOL gfUserWantsToQuit = FALSE;

When the user click the "Stop this Now" button, then set:

        gfUserWantsToQuit= TRUE;

Now, in your endless loop,

fUserWantsToQuit= FALSE;
while( 1 ) {
      //... do some work ...
      PumpMessagesForUI();
      if ( gfUserWantsToQuit ) {
            break;  // exit the endless loop
      }
      //... do some work ...
}

Besides allowing the user to click buttons, pumping messages will let him drag your window around the screen and so forth -- just like a real program!

-- Dan
0
 

Author Comment

by:Logick
ID: 9643843
Thanks it's working ^_^V
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

708 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

12 Experts available now in Live!

Get 1:1 Help Now