RJV
asked on
Adjusting window sizes
How can one adjust the window sizes with code such as one does with the cursor/mouse, be it of the main (mainframe) window or of internal windows such as of the MDI type? The idea is to be able to:
- Accompany the adjustments of the main window with
child windows, when the user adjusts the main one
- Be able to stop any window resizing altogether
Thanks in advance for your input!
RJV
- Accompany the adjustments of the main window with
child windows, when the user adjusts the main one
- Be able to stop any window resizing altogether
Thanks in advance for your input!
RJV
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Phillip,
Please correct me if I'm wrong, but aren't your suggestions dependent on events? Namely, if the user does the changing. How, however, does one do one's own changing, to simulate that of the user?
RJV
Please correct me if I'm wrong, but aren't your suggestions dependent on events? Namely, if the user does the changing. How, however, does one do one's own changing, to simulate that of the user?
RJV
AHhhh..... It would help if I would read the question. :)
You could do several SetWindowPos commands in a row. (e.g. Decreasing the x and increasing the cx simultaneously) After every SetWindowPos call, the window should redraw.
CWnd::SetWindowPos
BOOL SetWindowPos( const CWnd* pWndInsertAfter, int x, int y, int cx, int cy, UINT nFlags );
Return Value
Nonzero if the function is successful; otherwise 0.
Parameters
pWndInsertAfter Identifies the CWnd object that will precede this CWnd object in the Z-order. This parameter can be a pointer to a CWnd or a Pointer to one of the following values:
wndBottom Places the window at the bottom of the Z-order. If this CWnd is a topmost window, the window loses its topmost status; the system places the window at the bottom of all other windows.
wndTop Places the window at the top of the Z-order.
wndTopMost Places the window above all nontopmost windows. The window maintains its topmost position even when it is deactivated.
wndNoTopMost Repositions the window to the top of all nontopmost windows (that is, behind all topmost windows). This flag has no effect if the window is already a nontopmost window.
See the "Remarks" section for this function for rules about how this parameter is used.
x Specifies the new position of the left side of the window.
y Specifies the new position of the top of the window.
cx Specifies the new width of the window.
cy Specifies the new height of the window.
Phillip
You could do several SetWindowPos commands in a row. (e.g. Decreasing the x and increasing the cx simultaneously) After every SetWindowPos call, the window should redraw.
CWnd::SetWindowPos
BOOL SetWindowPos( const CWnd* pWndInsertAfter, int x, int y, int cx, int cy, UINT nFlags );
Return Value
Nonzero if the function is successful; otherwise 0.
Parameters
pWndInsertAfter Identifies the CWnd object that will precede this CWnd object in the Z-order. This parameter can be a pointer to a CWnd or a Pointer to one of the following values:
wndBottom Places the window at the bottom of the Z-order. If this CWnd is a topmost window, the window loses its topmost status; the system places the window at the bottom of all other windows.
wndTop Places the window at the top of the Z-order.
wndTopMost Places the window above all nontopmost windows. The window maintains its topmost position even when it is deactivated.
wndNoTopMost Repositions the window to the top of all nontopmost windows (that is, behind all topmost windows). This flag has no effect if the window is already a nontopmost window.
See the "Remarks" section for this function for rules about how this parameter is used.
x Specifies the new position of the left side of the window.
y Specifies the new position of the top of the window.
cx Specifies the new width of the window.
cy Specifies the new height of the window.
Phillip
Also check out the OnSizing function, here you can stop the resizing of the window before it happens.
Phillip
Phillip
ASKER
Thanks, Phillip!
Adding the WS_THICKFRAME windows style allows a window to be re-sized. By removing this from the Mainframe window's styles, you can prevent this window from being resized. Further, the MINMAXINFO structure stores the maximum and minimum tracking size of a window. The WM_GETMINMAXINFO message is sent to a window when the size or position of that window is about to change. An application can over-ride the handler for this message to set a window's default minimum or maximum tracking size.
MORE INFORMATION
You can prevent the Mainframe window of an AppWizard-generated SDI application from being resized by following these steps:
Modify the IDR_MAINFRAME menu to add a top-level menu item (F&reeze!) with an ID of ID_FREEZE.
Add a public Boolean data member (say, BOOL freezeState) to the CMainFrame class to keep track of the current state of the application. Initialize freezeState to FALSE in the constructor of the CMainFrame class.
Provide a command handler for the 'Freeze' menu item as follows:
void CMainFrame::OnFreeze() {
char* lpszFreeze = "F&reeze!";
char* lpszUnFreeze = "&UnFreeze!";
CMenu* pmenu = GetMenu();
if (!freezeState)
{
freezeState = TRUE;
pmenu->ModifyMenu(ID_FREEZ
lpszUnFreeze);
DWORD style = ::GetWindowLong(this->m_hW
// Remove the thick frame style and the Minimize, Maximize buttons
style &= ~(WS_MAXIMIZEBOX|WS_MINIMI
::SetWindowLong(this->m_hW
} else {
freezeState = FALSE;
pmenu->ModifyMenu(ID_FREEZ
lpszFreeze);
DWORD style = ::GetWindowLong(this->m_hW
// Add the thick frame style and the Minimize, Maximize buttons
style |= (WS_MAXIMIZEBOX|WS_MINIMIZ
::SetWindowLong(this->m_hW
}
DrawMenuBar();
}
Provide a handler for the WM_GETMINMAXINFO message as follows:
void CMainFrame::OnGetMinMaxInf
if (freezeState)
{
RECT rc;
GetWindowRect(&rc);
lpMMI->ptMaxSize.x = rc.right - rc.left;
lpMMI->ptMaxSize.y = rc.bottom - rc.top;
lpMMI->ptMaxPosition.x = rc.left;
lpMMI->ptMaxPosition.y = rc.top;
lpMMI->ptMinTrackSize.x = rc.right - rc.left;
lpMMI->ptMinTrackSize.y = rc.bottom - rc.top;
lpMMI->ptMaxTrackSize.x = rc.right - rc.left;
lpMMI->ptMaxTrackSize.y = rc.bottom - rc.top;
}
CFrameWnd::OnGetMinMaxInfo
}
If the mainframe is maximized, disable the Freeze menu option because there is no point in making the window non-resizable because a maximized window cannot be resized anyway:
void CMainFrame::OnSize(UINT nType, int cx, int cy) {
CFrameWnd::OnSize(nType, cx, cy);
CMenu* pmenu = GetMenu();
if (nType == SIZE_MAXIMIZED)
pmenu->EnableMenuItem(ID_F
else
pmenu->EnableMenuItem(ID_F
DrawMenuBar();
}
NOTE: The steps to prevent the Mainframe window of an MDI application from being resized should be identical to the steps listed in this article. However, because there is more than one menu resource in an MDI application, you may want to design your application to add the 'Freeze' menu item to more than one menu resource.
Phillip