dialog box control size varies with the size of the window

Source: Internet
Author: User

We often find that when we maximize the window, the controls inside are not changed, and then I'll introduce a solution to the problem, and we'll generally disable the window's Maximize button, which is the window is not maximized, but sometimes we still need to maximize the window. Below we can resolve this issue by adding wm_size messages.
1 adding in XXDLg.h
afx_msg void OnSize (UINT nType, int cx, int cy);
2 adding in XXDLg.h
On_wm_size () or on_message (wm_size,onsize)
3 Add the following member variable in the Xxdlg class
Point Osize
4 in the Xxdlg class OnInitDialog () add the following code

    CRect rect;      GetClientRect(&rect);  //获取客户端区域的大小    oSize.x = rect.right - rect.left;  //初始窗口的宽度    oSize.y = rect.bottom - rect.top;  //初始窗口的高度
5在XXDlg类中添加以下成员函数

"'
void Xxdlg::onsize (UINT nType, int cx, int cy)
{
Cdialog::onsize (NType, CX, CY);
if (ntype==size_restored | | ntype==size_maximized)//Type of window change
{

    float ratio[2];  Rate of Change point newdialogsize;      The size of the new window CRect newrect;  GetClientRect (&newrect);  Gets the size of the new client area newdialogsize.x = Newrect.right-newrect.left;   The width of the new window newdialogsize.y = newrect.bottom-newrect.top;      The height of the new window//To the current dialog box with the size ratio of the previous dialog box ratio[0] = (float) newdialogsize.x/osize.x;      RATIO[1] = (float) newdialogsize.y/osize.y;      CRect Rect;      int WOC;  Left and right corner data CPoint oldtlpoint, Newtlpint;  Upper left corner CPoint Oldbrpoint, Newbrpint;      Bottom right corner//List all controls HWND Hwndchild =:: GetWindow (M_hwnd,gw_child);          while (Hwndchild) {//get id WOC =:: GetDlgCtrlID (Hwndchild);  GetDlgItem (WOC)->getwindowrect (Rect);  Gets the area size of the control screentoclient (Rect);          Map to client area size Oldtlpoint = Rect.topleft ();          Newtlpint.x = Long (oldtlpoint.x*ratio[0]);          Newtlpint.y = Long (oldtlpoint.y*ratio[1]);          Oldbrpoint = Rect.bottomright (); Newbrpint.x = Long (oldbrpoint.X*ratio[0]);          Newbrpint.y = Long (oldbrpoint.y*ratio[1]);  Rect.setrect (Newtlpint,newbrpint);  Reset the control area size GetDlgItem (WOC)->movewindow (rect,true); Display to Window Hwndchild=::getwindow (Hwndchild, Gw_hwndnext);   Gets the handle of the next control} osize = Newdialogsize;   The new window size as the basis for the next change}

}

However, after many times the window changes, the inside of the control will be distorted, this problem has not been resolved!

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

dialog box control size varies with the size of the window

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.