-
November 4th, 2009, 03:51 AM
#1
window misplaced when it maximized.
I want to keep my SDI application's window always maximized.
So I disable the maximize button ,and maximized the window when it initially opened.
I did it as follows.
Code:
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
if( !CMDIFrameWnd::PreCreateWindow(cs) )
return FALSE;
cs.style &= ~WS_MAXIMIZEBOX;
return TRUE;
}
BOOL CMyApp::InitInstance()
{
// The main window has been initialized, so show and update it.
pMainFrame->ShowWindow(SW_SHOWMAXIMIZED);
pMainFrame->UpdateWindow();
return TRUE;
}
The window were shown with the wrong size.
It was higher than expected, therefore the status bar hided behind the system's task bar.
But, if we left the maximize button, the windows size will be right.
Why?
How can I keep the window maximized always?
Thanks.
-
November 4th, 2009, 05:57 AM
#2
Re: window misplaced when it maximized.
You can keep the window with WS_MAXIMIZEBOX style, and ignore Maximize - Restore commands:
Code:
void CMainFrame::OnSysCommand(UINT nID, LPARAM lParam)
{
if ( nID == SC_RESTORE || nID == SC_MAXIMIZE )
{
return;
}
CFrameWnd::OnSysCommand(nID, lParam);
}
-
November 4th, 2009, 08:48 PM
#3
Re: window misplaced when it maximized.
Originally Posted by Alex F
You can keep the window with WS_MAXIMIZEBOX style, and ignore Maximize - Restore commands:
Code:
void CMainFrame::OnSysCommand(UINT nID, LPARAM lParam)
{
if ( nID == SC_RESTORE || nID == SC_MAXIMIZE )
{
return;
}
CFrameWnd::OnSysCommand(nID, lParam);
}
Thanks.
But if ignore the SC_RESTORE, we can not restore the window when it minimized.
-
November 4th, 2009, 09:56 PM
#4
Re: window misplaced when it maximized.
Maybe we can do it by holding back the mouse action.
Code:
void CMainFrame::OnNcLButtonDblClk(UINT nHitTest, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if (nHitTest == HTCAPTION )
{
return;
}
CMDIFrameWnd::OnNcLButtonDblClk(nHitTest, point);
}
void CMainFrame::OnNcLButtonDown(UINT nHitTest, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if (nHitTest == HTMAXBUTTON)
{
return;
}
CMDIFrameWnd::OnNcLButtonDown(nHitTest, point);
}
There is one question left.
Why the task bar is misplaced when we disable the maximize box?
-
November 4th, 2009, 10:36 PM
#5
Re: window misplaced when it maximized.
In a nutshell: Window can be in a minimized, maximized state or something in between.
About WS_MAXIMIZEBOX style:
The name of the style is slightly misleading. This style allows toggling between maximized and last saved size.
In your case, window can be maximized or minimized; that is it.
BUT
For windows with WS_MAXIMIZEBOX style, system calculate maximum size based upon desktop working area to compensate for a task bar.
If you remove WS_MAXIMIZEBOX, window can have only set style and minimized. That is if frame is not resizable. System soes not bother to compensate, since you may want to run kiosk type of the application.
If you want both, you have to tell windows what maximum size you require despite removed WS_MAXIMIZEBOX. To do so, handle WM_GETMINMAXINFO message in a main frame. Retrieve required height using GetSystemMetrics(SM_CYMAXIMIZED). This returns height of the desktop not obscured by task bar.
In WM_GETMINMAXINFO handler, assign this value to ptMaxSize.y member of the MINMAXINFO structure.
Code:
//In a header declare variable to hold height:
protected: // control bar embedded members
CStatusBar m_wndStatusBar;
CToolBar m_wndToolBar;
int m_iDesktopHeight;
// call GetSystemMetrics from OnCreate or PreCreateWindow function.
//In a WM_GETMINMAXINFO handler:
void CMainFrame::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI)
{
// set maximum height
lpMMI->ptMaxSize.y = m_iDesktopHeight;
CMDIFrameWnd::OnGetMinMaxInfo(lpMMI);
}
This will set proper height even without WS_MAXIMIZEBOX style set.
Last edited by JohnCz; November 4th, 2009 at 10:40 PM.
There are only 10 types of people in the world:
Those who understand binary and those who do not.
-
November 4th, 2009, 10:38 PM
#6
Re: window misplaced when it maximized.
Originally Posted by tjuzhangrui
Maybe we can do it by holding back the mouse action.
Nope.
Mouse has nothing to do with it. see my prevoius post.
There are only 10 types of people in the world:
Those who understand binary and those who do not.
-
November 5th, 2009, 01:56 AM
#7
Re: window misplaced when it maximized.
Originally Posted by JohnCz
In a nutshell: Window can be in a minimized, maximized state or something in between.
About WS_MAXIMIZEBOX style:
The name of the style is slightly misleading. This style allows toggling between maximized and last saved size.
In your case, window can be maximized or minimized; that is it.
BUT
For windows with WS_MAXIMIZEBOX style, system calculate maximum size based upon desktop working area to compensate for a task bar.
If you remove WS_MAXIMIZEBOX, window can have only set style and minimized. That is if frame is not resizable. System soes not bother to compensate, since you may want to run kiosk type of the application.
If you want both, you have to tell windows what maximum size you require despite removed WS_MAXIMIZEBOX. To do so, handle WM_GETMINMAXINFO message in a main frame. Retrieve required height using GetSystemMetrics(SM_CYMAXIMIZED). This returns height of the desktop not obscured by task bar.
In WM_GETMINMAXINFO handler, assign this value to ptMaxSize.y member of the MINMAXINFO structure.
Code:
//In a header declare variable to hold height:
protected: // control bar embedded members
CStatusBar m_wndStatusBar;
CToolBar m_wndToolBar;
int m_iDesktopHeight;
// call GetSystemMetrics from OnCreate or PreCreateWindow function.
//In a WM_GETMINMAXINFO handler:
void CMainFrame::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI)
{
// set maximum height
lpMMI->ptMaxSize.y = m_iDesktopHeight;
CMDIFrameWnd::OnGetMinMaxInfo(lpMMI);
}
This will set proper height even without WS_MAXIMIZEBOX style set.
Thanks, but in this way , we can restore the window by double clicking it's title-bar, and move it by draging it's title-bar.
This behavior is different from the window which is maximized by push the maximize button.
-
November 5th, 2009, 04:03 AM
#8
Re: window misplaced when it maximized.
Code:
void CMainFrame::OnSysCommand(UINT nID, LPARAM lParam)
{
if ( (nID == SC_RESTORE && (! IsIconic()) ) || nID == SC_MAXIMIZE )
{
return;
}
CFrameWnd::OnSysCommand(nID, lParam);
}
void CMainFrame::OnNcLButtonDblClk(UINT nHitTest, CPoint point)
{
// TODO: Add your message handler code here and/or call default
//CFrameWnd::OnNcLButtonDblClk(nHitTest, point);
}
-
November 5th, 2009, 08:09 AM
#9
Re: window misplaced when it maximized.
The pictures show the mainframe maximized but not the view. You need to maximize the view when you create it also.
-
November 5th, 2009, 08:06 PM
#10
Re: window misplaced when it maximized.
Originally Posted by Alex F
Code:
void CMainFrame::OnSysCommand(UINT nID, LPARAM lParam)
{
if ( (nID == SC_RESTORE && (! IsIconic()) ) || nID == SC_MAXIMIZE )
{
return;
}
CFrameWnd::OnSysCommand(nID, lParam);
}
void CMainFrame::OnNcLButtonDblClk(UINT nHitTest, CPoint point)
{
// TODO: Add your message handler code here and/or call default
//CFrameWnd::OnNcLButtonDblClk(nHitTest, point);
}
It works.
Thanks all for the help.
-
November 5th, 2009, 08:07 PM
#11
Re: window misplaced when it maximized.
Originally Posted by GCDEF
The pictures show the mainframe maximized but not the view. You need to maximize the view when you create it also.
Sure. I will do this next.
Thanks.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|