Lock the MFC Screen

1.1k Views Asked by At

I have an MFC Application in which I have Wizards which is created using CPropertySheet. I have few controls and 'Next' button. When I press 'Next' button I will be doing various operations, On that time, I want to lock the screen so that user won't be able to click or do any operations on the screen. Please suggest me some way to handle this scenario?

2

There are 2 best solutions below

0
On

You can 'lock' a window by using EnableWindow. That's only a single window, mind you, the user can still interact with other windows/applications for which you haven't called that function.

HWND hWnd;
CWnd *pWnd;

// do stuff

// lock window
::EnableWindow(hWnd, FALSE);

// do stuff

//unlock window
::EnableWindow(hWnd, TRUE);

// lock window
pWnd->EnableWindow(FALSE);

// do stuff

// unlock window
pWnd->EnableWindow(TRUE);
0
On

Best would be to invoke a dialog box using DoModal with 'Close' disabled and no buttons to discard the dialog. In that dialogbox you can actually give out some meaningful messages about the progress or even show a progress bar. This way you effectively lock out the user from doing anything with the application and also give him some feedback, so that he knows some work is being done.