Solved

Accessing buttons while another process is running

Posted on 2003-10-28
2
174 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

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: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
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.
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…

691 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