对话框大小改变时控件自动改变大小--EASYSIZE

来源:互联网 发布:淘宝兼职名片 编辑:程序博客网 时间:2024/06/07 07:07
Note that all this works exactly the same way with both CDialog and CPropertyPage


1、#include EasySize.h to your stdafx.h (or put it in your include directory and #include <EasySize.h> , which I recommend)
2、Add DECLARE_EASYSIZE anywhere in your class declaration:
class CEasySizeDemoDlg : public CDialog
{
DECLARE_EASYSIZE

...

}

3、Create an OnInitDialog handler if it doesn't already exist, and put this in the end of it: "INIT_EASYSIZE;" :
BOOL CEasySizeDemoDlg::OnInitDialog()
{
    CDialog::OnInitDialog();
...    
    INIT_EASYSIZE;
    return TRUE; // return TRUE  unless you set the focus to a control

4、

Create an OnSize handler and add the UPDATE_EASYSIZE; macro to it:
void CEasySizeDemoDlg::OnSize(UINT nType, int cx, int cy) 
{
    CDialog::OnSize(nType, cx, cy);
    UPDATE_EASYSIZE;

5(可选)

Optional - If you want your dialog to have a minimum size, then create an OnSizing handler and add the EASYSIZE_MINSIZE macro as below:
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)

6 添加消息响应

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:
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.
0 0
原创粉丝点击