Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: MFC VC++
hi guys,

i am using one while loop that should run till i press another button. that button member variable of type CButton ,and member variable name is m_stopvoice .
 
so i am writing like
 
while(m_stopvoice.EnableWindow(!=false))
{
}
 

if i press that button my execution should break from the while loop ...Is it the correct approach ....thanks in advance for valuable comment .....
Posted 20-Jun-12 20:54pm
Comments
Member 9102753 at 21-Jun-12 4:00am
   
Please Reply for the above query ...
Richard MacCutchan at 21-Jun-12 4:02am
   
Be patient, people answer in their own time and at no cost to you.
Richard MacCutchan at 21-Jun-12 4:03am
   
Why are you checking for the Window's enabled status rather than reacting when it's pressed?

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

When using infinite loops with Windows GUI application, you must ensure that Windows messages are processed during loop execution. If not, you can't check for events like pressed button.
 
The common approach to realize such loops is using them inside an own thread (worker thread if no GUI operations must be performed from inside the loop). While the worker thread is running it should check for a terminate event that is signaled by the main thread when the button is pressed or your application terminates.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 768
1 OriginalGriff 420
2 CPallini 275
3 George Jonsson 226
4 Richard Deeming 145
0 OriginalGriff 5,450
1 CPallini 4,500
2 Sergey Alexandrovich Kryukov 4,272
3 George Jonsson 3,057
4 Gihan Liyanage 2,445


Advertise | Privacy | Mobile
Web03 | 2.8.140916.1 | Last Updated 21 Jun 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100