Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Window Resizing

Status
Not open for further replies.

psnead

Programmer
Jul 5, 2000
41
DK
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?

thanks.
 
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

DialogControl = GetDlgItem(IDC_EDIT1);
ResizeControl(DialogControl, this->EditRect, this->DialogRect, this);

DialogControl = GetDlgItem(IDC_LIST1);
ResizeControl(DialogControl, this->ListRect, this->DialogRect, this);

DialogControl = GetDlgItem(IDC_ATLAS_STATIC);
ResizeControl(DialogControl, this->HeadingRect, this->DialogRect, this);
}
else
DialogSized = true;

this->GetWindowRect(this->DialogRect);

}

void ResizeControl(CWnd *Control, const CRect ControlSize, CRect OldSize, CWnd* ParentWindow)
{

/**************************************************
*
* 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;

ParentWindow->GetWindowRect(NewDialogSize);

if(NewDialogSize.Height() > OldSize.Height())
{
// Calculate scaling factors

XScale = (float)NewDialogSize.Width() / (float) OldSize.Width();
YScale = (float)NewDialogSize.Height() / (float)OldSize.Height();

// Calculate New control size and positions

NewWidth = (int)(ControlSize.Width() * XScale);
NewHeight = (int)(ControlSize.Height() * YScale);

XPosition = (int) ((float) ControlSize.left * XScale);
YPosition = (int) ((float) ControlSize.top * YScale);

RedrawControl.left = XPosition;
RedrawControl.top = YPosition;
RedrawControl.right = XPosition + NewWidth;
RedrawControl.bottom = YPosition + NewHeight;

Control->MoveWindow(RedrawControl,TRUE);
}
else
{
Control->MoveWindow(ControlSize,TRUE);
}
}

I hope this Helps.

SMA
 
Add CDialog::OnGetMinMaxInfo(.....)
try... try.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top