Gold mine of Visual C++ tricks!
How to disable maximizing the dialog from Task manager?
![]()
Its not mandatory for every windows citizen to have maximize button.
For instance, Windows calculator. But do you know that via taskmgr we could maximize any dialogs? Even you can maximize the dialog which doesn’t have maximize style. Its a master piece of QA team to make the dialog look weired. Well how to prevent it?
![]()
You can do it by handling – WM_GETMINMAXINFO message. Before resizing, this message is fired to the dialog to get the minimum and maximum window dimensions. Since, we don’t need to change our dimensions, we have to set the max dimensions as current window dimension. Have a look at the code snippet.
// Message map
BEGIN_MESSAGE_MAP(CRabbitDlg, CDialog)
...
ON_WM_GETMINMAXINFO()
END_MESSAGE_MAP()
void CRabbitDlg::OnGetMinMaxInfo( MINMAXINFO FAR* pMinMaxInfo )
{
// Window rect.
RECT rect = { 0 };
GetWindowRect( &rect );
CRect WindowRect( &rect );
// Set the maximum size. Used while maximizing.
pMinMaxInfo->ptMaxSize.x = WindowRect.Width();
pMinMaxInfo->ptMaxSize.y = WindowRect.Height();
// Set the x,y position after maximized.
pMinMaxInfo->ptMaxPosition.x = rect.left;
pMinMaxInfo->ptMaxPosition.y = rect.top;
}
![]()
There is one small known issue – if we maximize via taskmgr, the window remains same, but the title bar will be painted like maximized.
![]()
Targeted Audience – Intermediate.
| Print article | This entry was posted by Jijo Raj on August 20, 2008 at 5:42 pm, and is filed under MFC. Follow any responses to this post through RSS 2.0. You can leave a response or trackback from your own site. |

about 2 years ago
Use this to avoid the titlebar painting problem…
void CRabbitDlg::OnWindowPosChanging(WINDOWPOS FAR* lpwndpos)
{
ModifyStyle( WS_MAXIMIZE, 0 );
CDialog::OnWindowPosChanging(lpwndpos);
}
about 2 years ago
Wow!!!
Thanks a lot for the info. I’ll update the post.
Regards,
Jijo.
about 1 year ago
There is one more issue with Jijo’s solution.
Lets’ imagine we first minimize a window from TaskManager, then maximize it. Since window is initially in minimized state:
RECT rect = { 0 };
GetWindowRect( &rect ); /*window is curently minimized, rect will not contain valid coordinates.*/
CRect WindowRect( &rect );
// Set the maximum size. Used while maximizing.
pMinMaxInfo->ptMaxSize.x = WindowRect.Width();
pMinMaxInfo->ptMaxSize.y = WindowRect.Height();
/*Invalid values (likely, zeroes?) are placed in pMinMaxInfo->ptMaxSize.x,y*/
// Set the x,y position after maximized.
pMinMaxInfo->ptMaxPosition.x = rect.left;
pMinMaxInfo->ptMaxPosition.y = rect.top;
/*Invalid values (likely, some negative numbers) are placed in pMinMaxInfo->ptMaxPosition.x,y*/
As a result, the window will never be displayed again.
about 1 year ago
One way to solve the issue that Knjaz brings up is to use the GetWindowPlacement API instead to get the normal restored-position rect.
void CRabbitDlg::OnGetMinMaxInfo( MINMAXINFO FAR* pMinMaxInfo )
{
WINDOWPLACEMENT lpwndpl;
GetWindowPlacement(&lpwndpl);
CRect WindowRect(&lpwndpl.rcNormalPosition);
// Set the maximum size. Used while maximizing.
pMinMaxInfo->ptMaxSize.x = WindowRect.Width();
pMinMaxInfo->ptMaxSize.y = WindowRect.Height();
// Set the x,y position after maximized.
pMinMaxInfo->ptMaxPosition.x = rect.left;
pMinMaxInfo->ptMaxPosition.y = rect.top;
}