I have a window that I want to resize horizontally, but not vertically, like the Windows Find File or Folders dialog. How do you keep a window from being resized vertically?
To resize a window in one or both directions, the method I use is to create a CRect class member for the window and initialise it with the original size of the window. I then use this as a reference for all resizing activities.
Override the OnSize message handler for the window that you wish to resize. Use the windows CRect member variable as a basis for your resizing calculations and then use the MoveWindow function to force the resizing of the window to the desired size.
Don't forget that the controls within the window will require resizing consequently a CRECT object will be needed for each control as well.
The functions below are examples of the resize functions and appraoch that I use.
void xxxx::OnSize(UINT nType, int cx, int cy)
{
CDialog::OnSize(nType, cx, cy);
CWnd* DialogControl;
if(this->DialogSized == true)
{
this->Invalidate( TRUE ); // this effectively clears the client area prior
// to moving and resizing the dialog controls
/**************************************************
*
* This function both moves and resizes an
* individual dialog control. The function uses
* the Parent windows new size and the Parents
* size prior to the resize to determine the
* scaling factor to be used in the resizing of
* the control.
*
* Formal Parameters : -
* a. Pointer to the control to be moved & scaled
* b. CRect Containing default size data of the
* control
* c. CRect Containing the size of the Parent
* Window prior to resizing.
* d. Pointer to the Parent Window to enable the
* retrieving of the new window size.
*
***************************************************/
float XScale, YScale;
int NewWidth = 0, NewHeight = 0;
int XPosition = 0, YPosition = 0;
CRect NewDialogSize, RedrawControl;
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.