Click here to Skip to main content
15,891,976 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.
Posted
Comments
aamswe 15-Apr-11 5:52am    
I have tried few methods CWaitCursor, SetCursor(), BeginWaitCursor(), but all are not working.
MFC-MDI application does not support wait cursor?

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[^]
 
Share this answer
 
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);


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);


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


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


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.
 
Share this answer
 
v2
Comments
aamswe 15-Apr-11 7:07am    
This solution is usefull but getting memory error on

//re-enable the main window
AfxGetMainWnd()->EnableWindow(TRUE);
what could be the reason?
Olivier Levrey 15-Apr-11 7:37am    
I updated my answer.
mbue 15-Apr-11 13:58pm    
Quite right, but there are two things to distinquish: 1) loading inline 2) loading in thread. for 1) you dont need to enable/disable any window, because there is no interaction until the loading is ready. 2) you should disable the controls particular to quit the application on the regular way (by press the close button or menu item). otherwise using a progress window to terminate the loading.
Regards.
Olivier Levrey 16-Apr-11 6:35am    
I agree on point 1. Since OP asked about disabling interactions, I supposed he was using a thread, so I didn't mention that.

I am not sure I understood you about point 2.

Progress window is of course the best way.
mbue 16-Apr-11 8:59am    
Imagine you have a full screen window. Now you start such an operation. A disabled window cannot be moved or minimized at all. The window now is blocking the entire screen. The same is when a modal dialog pops up. This is a mayor bug in windows design.
Regards.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900