How to create a maximized window which the user cannot restore
For my KidType application, I needed to create a full-screen window which a child could not accidentally close or otherwise interfere with by random poking of the keyboard and mouse.
This proved more difficult than I thought. I initially tried to create a window (using MFC) which had no WS_SYSMENU style and was initially maximized. This worked although the window could still be moved by dragging the titlebar even though it was maximized. How odd.
After fiddling with window styles for an hour or so, I realised that it is not possible to create a window which is maximized but has no system menu.
My solution is to create the window with no system menu (ie. remove the WM_SYSMENU style which also removes the minimize, maximize and close buttons) and then intercept messages so the user cannot move it.
First create a window with no system menu. This is done in the PreCreateWindow function like this:
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
if( !CFrameWnd::PreCreateWindow(cs) )
return FALSE;
// Remove system menu, minimize, maximize and close buttons.
cs.style &= ~WS_SYSMENU;
// Remove menu bar.
cs.hMenu = 0;
return TRUE;
}
Next, I open the window initially maximized. This is done by changing the argument of the ShowWindow command in CMyApp::InitInstance(). The new line should look like this:
m_pMainWnd->ShowWindow(SW_SHOWMAXIMIZED);
Then I wrote a message handler for the WM_SYSCOMMAND message to prevent the window from being moved or restored:
void CMainFrame::OnSysCommand(UINT nID, LPARAM lParam)
{
UINT cmd = nID & 0xFFF0;
if(cmd == SC_RESTORE || cmd == SC_MOVE)
return;
CFrameWnd::OnSysCommand(nID, lParam);
}
Note that I check for SC_RESTORE as well as SC_MOVE because even though the restore button is gone, the user can still restore by double-clicking the title bar.

Thanks. This really helped me.