MFC按钮onclick处理程序
MFC button onclick handler
我有2个mfc按钮,我想在3D stl文件加载时隐藏,然后在stl加载完成时再次显示按钮。这是为了防止用户在正在加载模型时重新加载模型。
代码片段如下
{ // change control state when model loads
((CButton *)this->GetDlgItem(IDC_RELOAD_STOCK_BUTTON))->ShowWindow(SW_HIDE);
((CButton *)this->GetDlgItem(IDOK))->ShowWindow(SW_HIDE);
UpdateWindow();
}
// this process takes few seconds to load the file in the memory
customStockModel.LoadFile(pathName.GetBuffer(pathName.GetLength()));
{
// change control state when the model has loaded
((CButton *)this->GetDlgItem(IDC_RELOAD_STOCK_BUTTON))->ShowWindow(SW_SHOW);
((CButton *)this->GetDlgItem(IDOK))->ShowWindow(SW_SHOW);
UpdateWindow();
}
按钮确实像我期望的那样隐藏并重新出现,但是当我单击隐藏的按钮区域时,当按钮控件重新出现在屏幕上时,onclick处理程序立即被调用。看起来点击消息是排队的,一旦按钮被激活,MFC调用处理程序。我哪里做错了?
理想情况下,您应该在线程中读取文件-这将允许您的应用程序正常刷新自身并处理消息。现在,如果您不确定这一点(多线程是困难的),您可以定期调用length函数中的以下函数来清除消息循环。
BOOL YourClass::DoEvents()
{
MSG msg;
while (::PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
if (msg.message == WM_QUIT)
{
return FALSE;
}
if (!AfxGetApp()->PreTranslateMessage(&msg))
{
::TranslateMessage(&msg);
::DispatchMessage(&msg);
}
}
return TRUE;
}
它会工作,但"合适的程序员"会尖叫当他们看到这个!祝你好运
相关文章:
- 获取日期异步信号安全吗?如果在信号处理程序中使用,它会导致死锁吗
- 如何在信号处理程序和普通函数中对全局变量进行互斥读写操作
- 为什么我的 IExtractIcon 处理程序没有被调用?
- 在遍历处理程序的向量时注册和注销处理程序
- 有可能在信号处理程序中设置promise吗
- 在信号处理程序中捕获C++未处理的异常并恢复应用程序
- 在C++程序中使用的迭代器中未处理的异常
- 有关图像处理应用程序的硬件和软件安全性的建议
- 通过安装信号处理程序关闭多线程应用程序
- QDateTime::toString() 在退出处理程序中使用时失败
- 如何在 WindowProc 处理程序中区分箭头键和数字键盘?
- async_write完成处理程序最早何时完成?
- C++事件系统 - 多态事件和事件处理程序
- 使用信号处理程序处理从 FIFO 接收的数据
- 使用独立的 c++ 程序处理用 C 编写的字符设备驱动程序
- C 程序处理两个文件,而不是一个文件
- 是什么让这个程序处理缓慢?(C++)
- QT 中的应用程序>处理消息?
- MongoDB C++驱动程序处理副本集连接故障
- 使用 OpenCV 程序处理多页 PDF