Solved

Accessing buttons while another process is running

Posted on 2003-10-28
2
170 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
iSeries DB2 Query 2 91
Detect CR LF to each line 12 153
maven archtype selection in eclipse 1 53
ffmpeg - "rtsp://...... Operation not permitted" 4 74
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
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.

920 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

20 Experts available now in Live!

Get 1:1 Help Now