Autoadapt.h#pragma onceclass cautoadapt{public:cautoadapt (void), virtual ~cautoadapt (void);p ublic:void ReSize (HWND m _hwnd); void Initsize (HWND m_hwnd); Point old; Private:};
Autoadapt.cpp#include "stdafx.h" #include "AutoAdapt.h"/*mfc control Adaptive Window size usage: Adding such a member to the target class calls the Initsize function in the target initialization function// This is what you need. Call Resize*/cautoadapt::cautoadapt (void) {}cautoadapt::~cautoadapt (void) {}//This function in the WM_SIZE message handler function can also not call, see your own needs , if it is a window in a subwindow such as Tablectrl, call this function to fill the Tablectrl size//Add this function in the initialization function void Cautoadapt::initsize (HWND m_hwnd) {CRect rect; GetClientRect (M_hwnd,&rect); Fetch client area size Old.x=rect.right-rect.left; Old.y=rect.bottom-rect.top; int cx = GetSystemMetrics (Sm_cxfullscreen); int cy = GetSystemMetrics (Sm_cyfullscreen); CRect RT; SystemParametersInfo (spi_getworkarea,0,&rt,0); cy = Rt.bottom; MoveWindow (m_hwnd,0, 0, CX, cy,true); }//Add this function to the WM_SIZE message handler void Cautoadapt::resize (HWND m_hwnd) {float fsp[2]; Point Newp; Gets the size of the dialog box now CRect recta; GetClientRect (M_HWND,&RECTA); Fetch client area size Newp.x=recta.right-recta.left; Newp.y=recta.bottom-recta.top; Obtain multiples of fsp[0]= (float) newp.x/old.x; fsp[1]= (float) newp.y/old.y; CRect Rect; int WOC; Control marked CPoint oldtlpoint,tlpoint; Upper left corner CPoint Oldbrpoint,brpoint; Lower right corner HWND Hwndchild=::getwindow (M_hwnd,gw_child); List all controls while (Hwndchild) {woc=::getdlgctrlid (hwndchild);//Get id HWND Hctrl = GetDlgItem (m_hwn D,WOC); GetWindowRect (hctrl,&rect);//Handle the upper-left coordinate point point;point = Rect.topleft (); ScreenToClient (M_hwnd,&point); Oldtlpoint = point; Tlpoint.x = Long (oldtlpoint.x*fsp[0]); Tlpoint.y = Long (oldtlpoint.y*fsp[1]); Handle the lower-right coordinate point = Rect.bottomright (); ScreenToClient (M_hwnd,&point); Oldbrpoint = point; Brpoint.x = Long (oldbrpoint.x *fsp[0]); Brpoint.y = Long (oldbrpoint.y *fsp[1]); Rect.setrect (Tlpoint,brpoint); MoveWindow (hctrl,tlpoint.x,tlpoint.y,brpoint.x-tlpoint.x,brpoint.y-tlpoint.y,true); Hwndchild=::getwindow (Hwndchild, Gw_hwndnext); } OLD=NEWP; }
MFC Control Adaptive Window Size class