Solved

Accessing buttons while another process is running

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
notReplace  challenge 53 151
substring method in java 1 136
move a line in eclipse 3 109
Thin secure Windows 10 5 108
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
In this post we will learn different types of Android Layout and some basics of an Android App.
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.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

733 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