VC automatic change in the control position and size of the dialog box class

Source: Internet
Author: User

When you develop an application with VC, you often have to do something that can change the size of the dialog box, and this time requires the dialog box to change the size of the dialog box changes in their position and size. If you have fewer controls, you can add code to the dialog box's OnSize () event to adjust the position and size of each control, but it would be a very painful thing if you had more controls on the dialog box. If there are many dialog boxes that can be resized in the program, then one of the OnSize () is written down, which can make the programmer crash!

To solve this problem, I wrote a dialog box class Clxdialog that automatically changes the position and size of the control. The dialog class that inherits from this class, as long as you make some simple settings for the control in OnInitDialog (), the Control on the dialog box changes its position and size as the size of the dialog box changes.

To save control information, I have defined a structure:

typedef struct _dlgControlTag
{
 int iId; // 控件ID
 int iFlag; // 标志,表示怎样改变控件的位置或者大小
 int iPercent; // 改变值占对话框改变值的百分比
} DLGCTLINFO, *PDLGCTLINFO;

Here are some explanations for the Iflag and ipercent in the structure. Where Iflag is the following enumeration value:

enum
{
 MOVEX = 0, // 控件在X方向(左右)移动
 MOVEY, // 控件在Y方向(上下)移动
 MOVEXY, // 控件在X方向和Y方向同时移动
 ELASTICX, // 控件在X方向(宽度)改变大小
 ELASTICY, // 控件在Y方向改(高度)改变大小
 ELASTICXY // 控件在X方向和Y方向同时改变大小
};

Ipercent represents a percentage change in the value of a dialog box. For example, a control's ipercent value is a 100,iflag value of Movex, and when the width of the dialog box changes to 100 units, the control moves 100 units in the x direction, or the ipercent value of one control is 100, The Iflag value is Elasticxy, so when the width and height of the dialog box changes to 100 units, the height and width of the control changes to 100 units.

The following are the functions that set the control information:

BOOL SetControlProperty(PDLGCTLINFO lp, int nElements);

It is very simple to use, add code similar to the following in the OnInitDialog () function of the dialog box:

// 控件信息数组
static DLGCTLINFO dcMenuGroup[] =
{
 {IDOK, MOVEX, 100},
 {IDCANCEL, MOVEX, 100},
 {IDC_BUTTON1, MOVEX, 50},
 {IDC_BUTTON1, MOVEY, 100},
 {IDC_EDIT1, ELASTICX, 100},
 {IDC_EDIT2, ELASTICX, 50},
 {IDC_EDIT3, ELASTICX, 50},
 {IDC_EDIT3, MOVEX, 50},
 {IDC_EDIT4, ELASTICY, 100},
 {IDC_EDIT5, ELASTICX, 100},
 {IDC_EDIT5, ELASTICY, 50},
 {IDC_EDIT6, ELASTICX, 100},
 {IDC_EDIT6, ELASTICY, 50},
 {IDC_EDIT6, MOVEY, 50},
};
// 设置控件信息
SetControlProperty(dcMenuGroup, sizeof(dcMenuGroup)/sizeof(DLGCTLINFO));

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.