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