Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Comments
Member 9102753 21-Jun-12 4:00am    
Please Reply for the above query ...
Richard MacCutchan 21-Jun-12 4:02am    
Be patient, people answer in their own time and at no cost to you.
Richard MacCutchan 21-Jun-12 4:03am    
Why are you checking for the Window's enabled status rather than reacting when it's pressed?

1 solution

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.
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900