MFC Control Adaptive Window Size class

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.