Cformview Dynamic Adjustment dialog box size and proportional adjustment of deployment controls

Source: Internet
Author: User

Dynamically adjust the size of the dialog box based on the cformview of a single document and adjust the deployment control proportionally

If you are developing a single-document-based program and use the cformview base class to display multiple windows, this document may be helpful.

1. Implement the dialog box to fill the customer Zone

When we add a resource dialog box, its size will not be adjusted as the window size is displayed in the customer area. When the frame size is smaller than its size, a scroll bar appears, the operation is troublesome and the visual effect is not good.

Ideas

Adjust the size of the resource dialog box based on the size of the customer area, and set the size of the customer area by the parent framework.

Procedure

1. Set the frame size based on the screen resolution

Note that we cannot change the showwindow parameter sw_show in initinstance to sw_showmaximized directly. Although the window is maximized, we can use getclientrect in cformview to see that the size of the customer zone is still the original size.

If you set the frame size in the precreatewindow or oncreate function, it does not work.

The correct method is to reload ongetminmaxinfo in mainframe and set the window size according to the screen resolution.

// Set the frame size based on the screen resolution

Voidcmainframe: ongetminmaxinfo (minmaxinfo * lpmmi)

{

// Todo: add the message processing program code and/or call the default value here

Int Cx = getsystemmetrics (sm_cxscreen );

Int Cy = getsystemmetrics (sm_cyscreen );

Lpmmi-> ptmintracksize. x = Cx;

Lpmmi-> ptmaxtracksize. x = Cx;

Lpmmi-> ptmaxtracksize. Y = Cy;

Lpmmi-> ptmintracksize. Y = Cy;

Cframewnd: ongetminmaxinfo (lpmmi );

}

Set the initial coordinates of the window in precreatewindow.

CS. x = 0; CS. Y = 0;

2. Set the dialog box size based on the customer area size.

The oninitialupdate function in the view performs operations. This is the first function executed by the view.

Crect rect;

Getclientrect (& rect );

Movewindow (& rect );

3. dynamically adjust the widget size and position based on the dialog box size

You have obtained a method on the Internet and modified the method as follows:

Voidsetcontrolinfo (word ctrlid );

Protected:

Intm_old_cx, m_old_cy;

Cdwordarraym_control_info;

Initialize in oninitialupdate:

Csizesz = gettotalsize ();

M_old_cx = Sz. CX;

M_old_cy = Sz. Cy;

Function Definition for adding control information:

Voidctestformview: setcontrolinfo (word ctrlid ){

M_control_info.add (ctrlid );

}

Add the onmysize Function

Voidctestformview: onmysize (uint ntype, int CX, int CY ){

If (Cx = 0 | Cy = 0 ){

Cx = 800;

Cy = 600;

}

Floatdx_percent = (m_old_cx = 0 )? 1 :( float) (float) CX/(float) m_old_cx );

Floatdy_percent = (m_old_cy = 0 )? 1 :( float) (float) cy/(float) m_old_cy );

If (m_old_cx ){

Crect wndrect;

Cwnd * pwnd;

For (INTI = 0; I <m_control_info.getsize (); I ++ ){

Pwnd = getdlgitem (m_control_info [I]);

If (! Pwnd ){

Trace (_ T ("Control ID-% dnot"), m_control_info [I]);

Continue;

}

Pwnd-> getwindowrect (& wndrect );

Screentoclient (& wndrect );

Wndrect. Left = (INT) (wndrect. Left * dx_percent );

Wndrect. Right = (INT) (wndrect. Right * dx_percent );

Wndrect. Top = (INT) (wndrect. Top * dy_percent );

Wndrect. Bottom = (INT) (wndrect. Bottom * dy_percent );

Pwnd-> movewindow (& wndrect );

}

}

M_old_cx = Cx;

M_old_cy = Cy;

}

 

Add the Control ID to the oninitialupdate function.

Setcontrolinfo (idc_button1 );

......

Please note that,The initial size of the dialog box is the size of the dialog box we pulled out in the resource dialog box to know the scaling ratio.

Obtain the functions in cscrollview used for the initial size.GettotalsizeObtained.

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.