又好久没记录技术笔记了!
首先在属性对话框中border选择resize属性。
这时 窗体就可以通过鼠标改变大小了,但难的是窗体改变时,窗体上的控件也相应地按比例改变大小。
这里我将外国的人的源码贴在这里 ,大家一起学学(http://www.codeproject.com/KB/dialog/easysize.aspx)
Introduction
Have you ever thought of how annoying it actually was to spend a lot of time doing a basic GUI for your simple applications instead of focusing on the actual 'content'? Take for example a resizing dialog or property page. You need to write code for each control that will tell it where to go when the thing is resized, and this can take up a lot of time. Now I know that I'm not the first one to give a solution to this (CResizableDialog), but this article is on my approach.
Description
Basically, all you need to do is design your dialog the way you want it to look in the resource editor (don't forget to make it resizable), and then define how the controls will behave when the dialog is resized using one single macro for each control.
Usage
Note that all this works exactly the same way with both CDialog and CPropertyPage
-
#includeEasySize.h to your stdafx.h (or put it in your include directory and#include<EasySize.h> , which I recommend) - Add
DECLARE_EASYSIZEanywhere in your class declaration: - Create an
OnInitDialoghandler if it doesn't already exist, and put this in the end of it: "INIT_EASYSIZE;" : - Create an
OnSizehandler and add theUPDATE_EASYSIZE;macro to it: - Optional - If you want your dialog to have a minimum size, then create an
OnSizinghandler and add theEASYSIZE_MINSIZEmacro as below: - Now you have to create the "EasySize Map" (or whatever you want to call it) in which you will specify the behavior of each dialog item. It can be placed anywhere inside your class implementation. The map looks like this:
class CEasySizeDemoDlg : public CDialog
{
DECLARE_EASYSIZE
...
BOOL CEasySizeDemoDlg::OnInitDialog()
{
CDialog::OnInitDialog();
...
INIT_EASYSIZE;
return TRUE; // return TRUE unless you set the focus to a control
}
void CEasySizeDemoDlg::OnSize(UINT nType, int cx, int cy)
{
CDialog::OnSize(nType, cx, cy);
UPDATE_EASYSIZE;
}
void CEasySizeDemoDlg::OnSizing(UINT fwSide, LPRECT pRect)
{
CDialog::OnSizing(fwSide, pRect);
EASYSIZE_MINSIZE(280,250,fwSide,pRect);
}
//(in this example, 280 is the minimum width and 250 the
//minimum height we want our dialog to have)
BEGIN_EASYSIZE_MAP(class_name)
...
EASYSIZE(control,left,top,right,bottom,options)
...
END_EASYSIZE_MAP
The map from the demo application looks like this:
...
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
BEGIN_EASYSIZE_MAP(CEasySizeDemoDlg)
EASYSIZE(IDC_TITLE,ES_BORDER,ES_BORDER,
ES_BORDER,ES_KEEPSIZE,ES_HCENTER)
EASYSIZE(IDC_RADIO1,ES_BORDER,ES_BORDER,
ES_KEEPSIZE,ES_KEEPSIZE,0)
EASYSIZE(IDC_RADIO2,ES_BORDER,ES_BORDER,
ES_KEEPSIZE,ES_KEEPSIZE,0)
EASYSIZE(IDC_CONTENT,ES_BORDER,ES_BORDER,
ES_BORDER,ES_BORDER,0)
EASYSIZE(IDC_STATUSFRAME,ES_BORDER,ES_KEEPSIZE,
ES_BORDER,ES_BORDER,0)
EASYSIZE(IDC_STATUS,ES_BORDER,ES_KEEPSIZE,
ES_BORDER,ES_BORDER,0)
EASYSIZE(IDOK,ES_KEEPSIZE,ES_KEEPSIZE,
ES_BORDER,ES_BORDER,0)
EASYSIZE(IDCANCEL,ES_KEEPSIZE,ES_KEEPSIZE,
ES_BORDER,ES_BORDER,0)
EASYSIZE(IDC_MYICON1,ES_BORDER,IDC_RADIO2,IDC_CONTENT,
IDC_STATUSFRAME,ES_HCENTER|ES_VCENTER)
EASYSIZE(IDC_MYICON2,ES_BORDER,ES_BORDER,IDC_TITLE,
ES_KEEPSIZE,ES_HCENTER)
END_EASYSIZE_MAP
///////////////////////////////////////////////////////////////
// CEasySizeDemoDlg message handlers
...
Looks confusing? It's not once you get the point (and I know I'm not good at explaining it) Read on.
EASYSIZE Macro
The EASYSIZE macro is used in the EasySize Map to specify what behavior your controls will have on dialog resize. It looks like this: