Home > Software engineering >  MFC controls change with the window size for a few times after the controls on the top left corner?
MFC controls change with the window size for a few times after the controls on the top left corner?

Time:09-25

Do MFC controls after several times of changing with the window size operation control program, is a success, but try for several times, after the successful controls are crowded in the upper left corner, even finally could no longer see controls! Forget you help have a look at the great god, implementation method is as follows:
//header file definition: 
CRect m_rect;
Void RzSize (void);
POINT old;
In OnInitDialog () initialization:
GetClientRect (& amp; M_rect);
Old. X=m_rect. Right - m_rect. Left;
Old. Y=m_rect. Bottom - m_rect. Top;
MaxWindow=old;
Return TRUE;
//add a WM_SIZE message, call the custom function in the Onsize function
Void CControlSystemDlg: : OnSize (UINT nType, cx, int int cy)
{
CDialog: : OnSize (cx, nType, cy);

//TODO: Add your message handler code here
If (nType==SIZE_MINIMIZED)
{
return;
}
The else
{
RzSize ();
}

}
//custom RzSize () function
Void CControlSystemDlg: : RzSize (void)
{
Float FSP [2].
POINT Newp;//get the size of the dialog now
CRect recta;
GetClientRect (& amp; Recta);//in the client area size
Newp. X=recta. Right - recta. Left;
Newp) y=recta) bottom - recta. Top;
FSP [0]=(float) Newp. X/old. X.
FSP [1]=(float) Newp. Y/old. Y;
CRect the Rect.
Int woc.
CPoint OldTLPoint TLPoint;//the top left corner
CPoint OldBRPoint BRPoint;//at the bottom right
HWND hwndChild=: : GetWindow (m_hWnd, GW_CHILD);//list all control
While (hwndChild) {
Woc=: : GetDlgCtrlID (hwndChild);//ID
GetDlgItem (woc) - & gt; GetWindowRect (the Rect);
The ScreenToClient (the Rect);
OldTLPoint=the Rect. TopLeft ();
TLPoint. X=long (OldTLPoint. * x FSP [0]).
TLPoint. Y=long (OldTLPoint. * y FSP [1]).
OldBRPoint=the Rect. BottomRight ();
BRPoint. X=long (OldBRPoint. * x FSP [0]).
BRPoint. Y=long (OldBRPoint. * y FSP [1]).
The Rect. SetRect (TLPoint BRPoint);
GetDlgItem (woc) - & gt; MoveWindow (the Rect, TRUE);
HwndChild=: : GetWindow (hwndChild GW_HWNDNEXT);
}
Old=Newp;
}


CodePudding user response:

Controls are slowly ran didn't? Long (OldTLPoint. * x FSP [0]) that may have a problem, and old=Newp,

CodePudding user response:

Retain the original position, and always with original position calculation

CodePudding user response:

EASYSIZE codeproject search

CodePudding user response:

reference 1st floor donjin9 response:
control is slowly ran didn't? Long (OldTLPoint. * x FSP [0]) that may have a problem, and old=Newp,

Has examined the CPoint 'constructor CPoint (int initX, int initY) should be two type int, into an int (OldTLPoint. * x FSP [0]) also has the same problem, can trouble says, "why can the old=Newp directly? Should not have been put in old call OnSize dialog before the width and height? Thank you very much!!!!!!

CodePudding user response:

refer to the second floor schlafenhamster response:
reserves the original position, always use original position calculation

Whether can be understood as the RzSize last line (void) function of the old=newp removal? This approach is that the control will be faster to the upper left corner focus!!!!!!

CodePudding user response:

The
reference 3 floor VisualEleven response:
codeproject search EASYSIZE

Thank you very much! This way I try!

CodePudding user response:

New window size must be calculated, and the initial window can't and the previous calculation, each computed float will be truncated loss of accuracy,

CodePudding user response:

"Keep original position, and always with original position calculation"
That do not use
CRect recta;
GetClientRect (& amp; Recta);//in the client area size
Newp. X=recta. Right - recta. Left;
Newp) y=recta) bottom - recta. Top;

CodePudding user response:

The proposal USES DUILIB UI interface library to do it, there is a layout manager, adaptive control, don't need you to write code management, anyhow write interface with DUILIB is very convenient

CodePudding user response:

Just write a class, you can refer to the child window with the parent window scaling management class

CodePudding user response:

You can refer to this link http://blog.csdn.net/xianglitian/article/details/5667015 (I) is done with this anyway, also can use EASYSIZE, the general idea is to record control original size, on the basis of the original size proportional to zoom in,
  • Related