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):
AfxGetMainWnd()->EnableWindow(FALSE);
...
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:
EnableWindow(FALSE);
...
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
.