Solved

Accessing buttons while another process is running

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Question regarding Copy/Paste 16 96
Include multiple hostnames in this command? 3 55
viewing source code from eclipse 13 110
Path of Workbook 3 86
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: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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 shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

839 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