我怎样才能保持我的运行函数,直到我单击 c++ 形式的按钮
How can I hold my running function until I click the button in c++ form?
我正在使用.net Framework 4和Visual Studio 2010。我正在使用 c++ 表单。我的代码是这样的:
int k = 0;
void writeFunction(int &k){
++k;
textbox1->text = Convert::toString(k);
//i want to suspend writeFunction in there, until i click the button1 which is on Form1
//because i don't want to stop function, it has to wait to click
//after i clicked the button1 , the program continue to run code here
writeFunciton(k);
}
你能添加更多关于你的程序的细节吗?您使用什么框架来生成表单,按钮按下如何与您的代码交互?
例如,如果您使用的是Qt,则可以使用信号和插槽将按下按钮与您的方法联系起来。根据框架的不同,可能会有其他适当的答案。
通常,我建议使用线程库来同步代码。
暂停 GUI 功能是不明智的。而不是在窗体类中使用操作状态变量,例如
enum OperationState
{
os_normal,
os_pointselection,
os_event1,...
}
调用文本框后>=...切换到选择状态,并使用此状态跟踪鼠标状态,例如单击后单击鼠标单击检查os_selection状态,然后继续您的职责。
相关文章:
- QTreeView幻灯片多选后无法使用单击选择
- WinAPI 在单击第一个对话框上的按钮控件并销毁第一个对话框后创建第二个对话框
- QML TableView 使用 QtQuick.Controls 2 单击行
- ImGui 在单击按钮后冻结
- 有没有办法区分Qt小部件是通过鼠标单击还是通过按表键获得焦点?
- 我想使用此代码单击某个特定窗口,但它无法正常工作
- 如何在QSplashScreen中禁用鼠标单击
- 单击一个按钮后创建一个按钮
- C++鼠标单击时的屏幕截图不起作用
- 我的主窗口在创建时或单击更新区域时是否会收到编辑控件?
- 标签检测鼠标单击 c++
- 如何将我的程序添加到文件和文件夹的macOS右键单击菜单?
- 使用 SFML 在矩形的矢量中查找鼠标单击量
- 在单击 QPushButton 时调用带有参数的函数
- 如何在单击按钮FLTK的确切时刻获得小部件的值
- 如何使用鼠标单击选择多个 QLabel 对象?
- WM_PAINT基于按钮单击
- 在使用 c++ 的 win32 api 中,我想跟踪双击和三次单击等
- 如何获得鼠标光标连接时按下左键单击和在C++中释放左键单击时?
- 在 Win32 应用中,如果未选择文件夹并且用户单击"确定",则文件夹选择对话框将关闭