The VC window can be adjusted freely. The specific code and detailed instructions in English are described in detail after use.
1. You can set the border size in the properties of the dialog box.
2. Add # include EasySize. h to the main form cpp, or add it to stdafx. h according to the original method.
3. define the main form
The following is a reference clip:
Class CEasySizeDemoDlg: public CDialog
{
DECLARE_EASYSIZE // Add this variable. If a compilation error occurs after it is added, refer to step 2.
4. In the OnInitDialog message function of the main form
The following is a reference clip:
BOOL CEasySizeDemoDlg: OnInitDialog ()
{
CDialog: OnInitDialog ();
...
INIT_EASYSIZE; // Add this
Return TRUE; // return TRUE unless you set the focus to a control
}
5. Reload the message WM_SIZE Function
The following is a reference clip:
Void CEasySizeDemoDlg: OnSize (UINT nType, int cx, int cy)
{
CDialog: OnSize (nType, cx, cy );
UPDATE_EASYSIZE; // Add this
}
6. If you want to adjust the window size to a maximum value, you can reload the onsizing message.
It seems that this message cannot be directly added in the Class Wizard. Of course, if you are too troublesome, do 1 as follows:
As early:
The following is a reference clip:
ON_WM_SIZE (); this is added below
ON_WM_SIZING ();
Then find:
The following is a reference clip:
Afx_msg void OnSize (UINT nType, int cx, int cy); add this
Afx_msg void OnSizing (UINT fwSide, LPRECT pRect );
Then add the event processing function:
The following is a reference clip:
Void CEasySizeDemoDlg: OnSizing (UINT fwSide, LPRECT pRect)
{
CDialog: OnSizing (fwSide, pRect );
EASYSIZE_MINSIZE (280,250, fwSide, pRect); // 280,250 is the minimum size,
// If you want to have the maximum size function, you can modify EasySize. h and write the maximum size according to the EASYSIZE_MINSIZE method.
}
Of course, you can also use the Class Wizard: Class Wizard-> classinfo (class information)-> Messagefilter-> Windows
Okay, then you can go back to Message maps to see if the message contains the WM_SIZING you want, ^ _ ^!
7. Add message ing
The following is a reference clip:
BEGIN_EASYSIZE_MAP (your main dialog name) // modify it to the class name of the main form
...
// Add a processing function for each widget that needs to be adjusted in the form hour
EASYSIZE (control, left, top, right, bottom, options) // The control ID
// Left: If you want to keep the position on the left of the main form, you can write ES_BORDER. If you want to keep the size unchanged, no special processing is added here. Write ES_KEEPSIZE. If you want to use the left of other spaces, as a benchmark, you can write the ID of the control.
// Top, right, bottom.
// Options controls the horizontal vertical center effect, such as ES_HCENTER | ES_VCENTER, with no special write 0
...
END_EASYSIZE_MAP
The usage of EASYSIZE (control, left, top, right, bottom, options) is as follows:
Where: control is the control ID value in the dialog box, left, top, right, and bottom parameters are the coordinates of the control position. The value can be ES_BOARD, ES_KEEPSIZE, or the control ID value. Options can be ES_HCENTER, ES_VCENTER combination, options can be set to 0.
ES_BOARD indicates the distance between the control and the dialog box border (hereinafter referred to as the border;
ES_KEEPSIZE indicates that the size of the control remains unchanged in the horizontal/vertical direction;
The Control ID value indicates the distance between the current control and the specified control;
ES_HCENTER indicates that the widget is horizontally centered within the specified position after scaling;
ES_VCENTER indicates that the control is vertically centered at the specified position after scaling;
For example:
EASYSIZE (IDOK, ES_BORDER, 0)
After scaling, the widget with the value of IDOK remains unchanged from the upper and lower sides of the boundary, and the horizontal and vertical dimensions are stretched;
EASYSIZE (IDOK, ES_BORDER, ES_HCENTER)
It indicates the control with the value of IDOK after scaling. The distance between the upper and lower positions of the border remains unchanged, the vertical direction is stretched, and the horizontal center is centered;
EASYSIZE (IDOK, ES_BORDER, ES_HCENTER | ES_HCENTER)
Controls with the value of IDOK after scaling are vertically centered and horizontally centered in the dialog box;
EASYSIZE (IDOK, ES_BORDER, ES_KEEPSIZE, ES_KEEPSIZE, ES_BORDER, 0)
Controls with the value of IDOK remain unchanged at the left and bottom of the boundary while maintaining the widget size;
EASYSIZE (IDOK, ES_BORDER, ES_KEEPSIZE, ES_BORDER, ES_BORDER, 0)
It indicates that after scaling, the widget with the value of IDOK remains unchanged from the left, right, and bottom of the boundary, horizontally stretched, and vertically unchanged;
EASYSIZE (IDOK, ES_BORDER, ES_BORDER, IDCANCEL, ES_BORDER, 0)
After scaling, the widget with the value of IDOK remains unchanged from the upper and lower left positions of the Boundary. The distance from the right side of the ID value of IDCANCEL remains unchanged, and the horizontal and vertical dimensions are stretched; (when using the specified control as the positioning parameter, make sure that the EASYSIZE of the specified control is before the macro)