CWaitCursor不适用于MFC-MDI应用程序 [英] CWaitCursor is not working for MFC-MDI application

查看:60
本文介绍了CWaitCursor不适用于MFC-MDI应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

朋友,

我有一个MFC-MDI应用程序,我想在其中在活动窗体视图上加载数据时使用CWaitCursor.当我打开表单时,它会加载数据,直到数据加载完成为止,我不想允许用户访问其他表单或其他功能.

谁能告诉我解决方案.

在此先感谢您.

Hi Friends,

I have a MFC-MDI application, in which I want to use CWaitCursor while loading data on active form view. When I open a form, it loads data and till the data loading complete I don''t want to allow user to access another forms or other functionality.

Can anyone tell me solution on it.

Thanks in advance.

推荐答案

在设计器中,禁用表格中的所有控件.在代码中,加载数据后,枚举表单上的所有控件,然后启用它们.这是我写的一篇文章,展示了如何以一种形式枚举控件:

枚举对话框或FormView中的控件 [
In the designer, make all of the controls in the form disabled. In the code, after the data is loaded, enumerate all of the controls on the form, and enable them. Here''s an article I wrote that shows how to enumerate controls in a form:

Enumerate Controls In a Dialog Box or FormView[^]


CWaitCursor不会阻止用户单击,它只显示等待光标.

您可以在加载数据时禁用主窗口(如果使用模式对话框,则可以禁用当前模式对话框):

CWaitCursor doesn''t prevent user from clicking, it just displays the wait cursor.

You can disable your main window while your are loading your data (or the current modal dialog box if you are using a modal dialog box):

//disable the main window
AfxGetMainWnd()->EnableWindow(FALSE);
...
//re-enable the main window
AfxGetMainWnd()->EnableWindow(TRUE);



您必须确保始终到达EnableWindow(TRUE)(即使例如在加载过程中发生错误),否则您的应用程序将被阻止.

或从模式对话框中:



You must ensure that you will always reach the EnableWindow(TRUE) (even if an error happens during your loading process for example), otherwise your application will be blocked.

Or from a modal dialog box:

//disable the dialog box
EnableWindow(FALSE);
...
//re-enable the dialog box
EnableWindow(TRUE);



同样的话:确保您将始终到达EnableWindow(TRUE).




Same remark for that one: make sure you will always reach EnableWindow(TRUE).


aamswe写道:

该解决方案很有用,但在重新启用主窗口AfxGetMainWnd()-> EnableWindow(TRUE)时出现内存错误. ;可能是什么原因?

This solution is usefull but getting memory error on //re-enable the main window AfxGetMainWnd()->EnableWindow(TRUE); what could be the reason?



检查AfxGetMainWnd返回的指针是否有效.通常,此函数返回您的应用程序创建的第一个窗口.如果第一个窗口被破坏,则该函数可以在该被破坏的窗口上返回旧指针.

实际上,AfxGetMainWndCWinApp派生的对象返回m_pMainWnd.例如,您可以从InitInstance更新此成员.

或者,您可以自己存储指针,而不使用AfxGetMainWnd.



Check that the pointer returned by AfxGetMainWnd is valid. Usually, this function returns the first window created by your application. If the first window is destroyed, the function can return an old pointer on that destroyed window.

Actually, AfxGetMainWnd returns m_pMainWnd from your CWinApp-derived object. You can update this member from InitInstance for example.

Or you can just store the pointer by yourself and not use AfxGetMainWnd.


这篇关于CWaitCursor不适用于MFC-MDI应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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