Click here to Skip to main content
13,052,558 members (56,184 online)
Rate this:
Please Sign up or sign in to vote.
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


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
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

Rate this: bad
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.

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170713.1 | Last Updated 21 Jun 2012
Copyright © CodeProject, 1999-2017
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