How to disable maximizing the dialog from Task manager?

20 08 2008

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.

Advertisements

Actions

Information

5 responses

25 08 2008
Nishad S

Use this to avoid the titlebar painting problem… šŸ™‚

void CRabbitDlg::OnWindowPosChanging(WINDOWPOS FAR* lpwndpos)
{
ModifyStyle( WS_MAXIMIZE, 0 );
CDialog::OnWindowPosChanging(lpwndpos);
}

25 08 2008
Jijo.Raj

Wow!!! šŸ˜€ Thanks a lot for the info. I’ll update the post.

Regards,
Jijo.

30 09 2008
Recent Links Tagged With "taskmanager" - JabberTags

[…] >> taskmanager Customize and tweak your Windows Vista Saved by juergenetu on Sun 28-9-2008 How to disable maximizing the dialog from Task manager? Saved by hehe5000 on Sun 28-9-2008 Task Manager Problems With XP Home Saved by snowbird122 on Wed […]

9 06 2009
Knjaz Drocheslav

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.

27 07 2009
James E

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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s




%d bloggers like this: