我如何检查是否单击了按钮? [英] How do i check if a button is clicked?
本文介绍了我如何检查是否单击了按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个CListCtrl,其中使用while循环将项目不断添加到列表中.现在我想停止在用户单击按钮时将项目添加到列表中.现在我希望使用if语句检查是否单击了按钮.在while循环中应使用哪种语句来检查是否单击了按钮?
I have a CListCtrl in which im continously adding items to the list using a while loop. Now i want to stop adding items to the list when the user clicks on a button.now i want a if statement to check if a button is clicked.what statement should i use in the while loop to check if a the button is clicked?
推荐答案
创建成员变量bool值以检查是否被单击.
单击后将其设为true.
现在,添加消息ON_BN_CLICKED并在该映射函数内部,将hte bool值的状态更改为true.
Create a member variable bool value to check whether it is clicked.
When it is clicked then make it as true.
Now add the message ON_BN_CLICKED and inside that mapped function, change the status of hte bool value as true.
连续添加-但是如何添加?
您是否在同一线程中使用循环?如果是,则无法轻松处理Stop事件.由于消息泵将没有时间来处理用户的操作,因此不会引发该事件.您要么需要在循环内调用PeekMessage
,要么使您的程序成为多线程.
阅读本文:
《多线程实用指南-第1部分》 [
Adding continously - but how?
Are you using a loop in the same thread? If yes, you cannot handle the Stop event that easily. The event would not be raised, since message-pump will not get time to process the user''s action. You either need to callPeekMessage
within the loop, or make your program multithreaded.
Read this article:
The Practical Guide to Multithreading - Part 1[^]
将调用过程放入看起来像按钮,如果按下则中断.
put a call procedure into the loop that looks to the button, and if pressed breaks.
这篇关于我如何检查是否单击了按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文