while循环应该一直运行,直到我按下另一个按钮为止,而条件是我写的正确与否 [英] while loop should run till i press another button for that while condition what i written is correct or not

查看:279
本文介绍了while循环应该一直运行,直到我按下另一个按钮为止,而条件是我写的正确与否的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我正在使用一个while循环,该循环应该一直运行到我按下另一个按钮为止.该按钮成员变量的类型为CButton,成员变量名称为m_stopvoice.

所以我写得像

while(m_stopvoice.EnableWindow(!= false))
{
}


如果我按下该按钮,我的执行应从while循环中中断...这是正确的方法吗?...在​​此先感谢您提出宝贵的意见.....

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

推荐答案

在Windows GUI应用程序中使用无限循环时,必须确保在循环执行期间处理Windows消息.如果没有,您将无法检查按下按钮之类的事件.

实现此类循环的常用方法是在自己的线程(如果不必从循环内部执行GUI操作,则在工作线程)中使用它们.当工作线程正在运行时,它应检查按下按钮或应用程序终止时主线程发出的终止事件.
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.


这篇关于while循环应该一直运行,直到我按下另一个按钮为止,而条件是我写的正确与否的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆