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

本文详细介绍如何使用EasySize控件来实现对话框及其控件的自动调整大小功能。通过六个步骤,包括包含头文件、声明宏、初始化、处理尺寸变化等,帮助读者快速掌握EasySize的使用方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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.
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值