【VS开发】EasySize使用设置CFormView空间自适应view窗口大小
2016-04-28 15:07
495 查看
1、在stdafx.h中引用EasySize.h头文件(同时将EasySize.h放到你的程序目录中)
2、在类定义中添加DECLARE_EASYSIZE
[cpp] view plain copy
class CEasySizeDemoDlg : public CDialog
{
DECLARE_EASYSIZE
``````
};
3、增加OnInitDialog处理函数,将INIT_EASYSIZE放到函数尾处。
[cpp] view plain copy
BOOL CEasySizeDemoDlg::OnInitDialog()
{
`````
INIT_EASYSIZE;
`````
}
4、增加OnSize函数,添加宏UPDATE_EASYSIZE
[cpp] view plain copy
void CEasySizeDemoDlg::OnSize(UINT nType, int cx, int cy)
{
CDialog::OnSize(nType, cx, cy);
UPDATE_EASYSIZE;
}
5、可选(最小化)
6、创建EasySize映射(map),在此map里,你可以制定每个对话框的行为。它可以放在类实现文件的任何位置。
BEGIN_EASYSIZE_MAP(class_name)
...
EASYSIZE(control,left,top,right,bottom,options)
...
END_EASYSIZE_MAP
源码如下:
[cpp] view plain copy
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_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_MYICON2,ES_BORDER,ES_BORDER,IDC_TITLE,ES_KEEPSIZE,ES_HCENTER)
EASYSIZE(IDC_CONTENT,IDC_TITLE,ES_BORDER,ES_BORDER,ES_BORDER,0)
EASYSIZE(IDC_MIDFRAME,ES_BORDER,ES_BORDER,IDC_CONTENT,ES_BORDER,0)
EASYSIZE(IDC_MIDRECT,ES_BORDER,ES_BORDER,IDC_CONTENT,ES_BORDER,0)
EASYSIZE(IDC_MYICON1,IDC_MIDRECT,IDC_MIDRECT,IDC_MIDRECT,IDC_MIDRECT,ES_HCENTER|ES_VCENTER)
END_EASYSIZE_MAP
EASYSIZE Macro
通过在EasySize Map中使用EASYSIZE宏来指定当对话框改变时control相应的行为,宏定义格式如下:
EASYSIZE(control,left,top,right,bottom,options)
参数1(Control):需要重新定位的control ID.
参数2、3、4、5(left, top, right and bottom ):这四个参数可以设定的值有其它控件的ID、特定的值如如ES_BORDER、ES_KEEPSIZE。
ES_BORDER :代表控件与边框的距离保持不变。
ES_KEEPSIZE:代表控件的宽度和高度保持不变,left/right只能设置其中一个为ES_KEEPSIZE,同理,top/bottom亦然。
参数6(options):ES_HCENTER, ES_VCENTER and 0的组合。
ES_HCENTER :代表控件在left/right之间水平居中,此时这两个参数都不能设置为ES_KEEPSIZE,控件的宽度保持不变。
ES_VCENTER 同理(垂直方向)。
Basically, if you specify an ID, the distance from the current control and the item designated by the ID will remain the same when the dialog is resized: The current control will 'stick' to the other item. ES_BORDER works the
same way as if you had specified a control ID, except that it's the distance between the current control and the dialog border that will be kept constant. Specifying ES_KEEPSIZE in, let's say left, will keep the width of the current control the same, and will
make the current control right-aligned to whatever you specified in right. The width (or height, if you specified ES_KEEPSIZE in top or bottom) of the current control will always remain what it is in the dialog resource. (I know this explanation sucks, but
look at the demo application if you are confused or post you question in the board below). Obviously ES_KEEPSIZE cannot be specified in both "left and right" or "top and bottom".
options can be a combination of ES_HCENTER, ES_VCENTER and 0 (use 0 if you don't want any of the other). ES_HCENTER horizontally centers the control between the two items specified in left and right (both of those can not be ES_KEEPSIZE!).
The width of the current control will always remain the same as in the dialog resource. ES_VCENTER works the same way, but for vertical centering (using top and bottom, and where the height will remain constant).
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
http://apps.hi.baidu.com/share/detail/30530119
这里需要解释的是宏EASYSIZE()的用法,其原型如下:
EASYSIZE(control,left,top,right,bottom,options)
该宏表示对ID值为control的控件实施缩放效果,缩放后的上下左右位置由control,left,top,right,bottom来确定,大小由option确定。
其中:control为对话框中的控件ID值,left,top,right,bottom四个参数为控件位置的坐标,其值可以选择ES_BOARD,ES_KEEPSIZE, 控件ID值三者之一。Options可以为ES_HCENTER, ES_VCENTER的结合,options可置0。
ES_BOARD表示控件与对话框边界(以下简称边界)的距离;
ES_KEEPSIZE表示控件水平/垂直方向上尺寸保持不变;
控件ID值表示当前控件与指定控件之间的距离;
ES_HCENTER表示缩放后控件在指定位置内水平居中;
ES_VCENTER表示缩放后控件在指定位置内垂直居中;
例如:
EASYSIZE(IDOK,ES_BORDER,ES_BORDER,ES_BORDER,ES_BORDER,0)
表示缩放后,值为IDOK的控件,距离边界上下左右位置保持不变,水平和垂直方向尺寸拉伸;
EASYSIZE(IDOK,ES_BORDER,ES_BORDER,ES_BORDER,ES_BORDER,ES_HCENTER)
表示缩放后,值为IDOK的控件,距离边界上下位置保持不变,垂直方向尺寸拉伸,水平居中;
EASYSIZE(IDOK,ES_BORDER,ES_BORDER,ES_BORDER,ES_BORDER,ES_HCENTER| ES_HCENTER)
表示缩放后,值为IDOK的控件,在对话框内垂直居中,水平居中;
EASYSIZE(IDOK,ES_BORDER,ES_KEEPSIZE,ES_KEEPSIZE,ES_BORDER,0)
表示缩放后,值为IDOK的控件,距离边界左、下方位置保持不变,同时保持控件尺寸;
EASYSIZE(IDOK,ES_BORDER,ES_KEEPSIZE, ES_BORDER,ES_BORDER,0)
表示缩放后,值为IDOK的控件,距离边界左、右、下方位置保持不变,水平方向尺寸拉伸,垂直方向尺寸不变;
EASYSIZE(IDOK,ES_BORDER,ES_BORDER,IDCANCEL,ES_BORDER,0)
表示缩放后,值为IDOK的控件,距离边界上下左位置保持不变,距离ID值为IDCANCEL的右方位置距离保持不变,水平和垂直方向尺寸拉伸;(当使用指定控件作为定位参数时候,确保指定控件的EASYSIZE在该宏前面)
2、在类定义中添加DECLARE_EASYSIZE
[cpp] view plain copy
class CEasySizeDemoDlg : public CDialog
{
DECLARE_EASYSIZE
``````
};
3、增加OnInitDialog处理函数,将INIT_EASYSIZE放到函数尾处。
[cpp] view plain copy
BOOL CEasySizeDemoDlg::OnInitDialog()
{
`````
INIT_EASYSIZE;
`````
}
4、增加OnSize函数,添加宏UPDATE_EASYSIZE
[cpp] view plain copy
void CEasySizeDemoDlg::OnSize(UINT nType, int cx, int cy)
{
CDialog::OnSize(nType, cx, cy);
UPDATE_EASYSIZE;
}
5、可选(最小化)
6、创建EasySize映射(map),在此map里,你可以制定每个对话框的行为。它可以放在类实现文件的任何位置。
BEGIN_EASYSIZE_MAP(class_name)
...
EASYSIZE(control,left,top,right,bottom,options)
...
END_EASYSIZE_MAP
源码如下:
[cpp] view plain copy
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_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_MYICON2,ES_BORDER,ES_BORDER,IDC_TITLE,ES_KEEPSIZE,ES_HCENTER)
EASYSIZE(IDC_CONTENT,IDC_TITLE,ES_BORDER,ES_BORDER,ES_BORDER,0)
EASYSIZE(IDC_MIDFRAME,ES_BORDER,ES_BORDER,IDC_CONTENT,ES_BORDER,0)
EASYSIZE(IDC_MIDRECT,ES_BORDER,ES_BORDER,IDC_CONTENT,ES_BORDER,0)
EASYSIZE(IDC_MYICON1,IDC_MIDRECT,IDC_MIDRECT,IDC_MIDRECT,IDC_MIDRECT,ES_HCENTER|ES_VCENTER)
END_EASYSIZE_MAP
EASYSIZE Macro
通过在EasySize Map中使用EASYSIZE宏来指定当对话框改变时control相应的行为,宏定义格式如下:
EASYSIZE(control,left,top,right,bottom,options)
参数1(Control):需要重新定位的control ID.
参数2、3、4、5(left, top, right and bottom ):这四个参数可以设定的值有其它控件的ID、特定的值如如ES_BORDER、ES_KEEPSIZE。
ES_BORDER :代表控件与边框的距离保持不变。
ES_KEEPSIZE:代表控件的宽度和高度保持不变,left/right只能设置其中一个为ES_KEEPSIZE,同理,top/bottom亦然。
参数6(options):ES_HCENTER, ES_VCENTER and 0的组合。
ES_HCENTER :代表控件在left/right之间水平居中,此时这两个参数都不能设置为ES_KEEPSIZE,控件的宽度保持不变。
ES_VCENTER 同理(垂直方向)。
Basically, if you specify an ID, the distance from the current control and the item designated by the ID will remain the same when the dialog is resized: The current control will 'stick' to the other item. ES_BORDER works the
same way as if you had specified a control ID, except that it's the distance between the current control and the dialog border that will be kept constant. Specifying ES_KEEPSIZE in, let's say left, will keep the width of the current control the same, and will
make the current control right-aligned to whatever you specified in right. The width (or height, if you specified ES_KEEPSIZE in top or bottom) of the current control will always remain what it is in the dialog resource. (I know this explanation sucks, but
look at the demo application if you are confused or post you question in the board below). Obviously ES_KEEPSIZE cannot be specified in both "left and right" or "top and bottom".
options can be a combination of ES_HCENTER, ES_VCENTER and 0 (use 0 if you don't want any of the other). ES_HCENTER horizontally centers the control between the two items specified in left and right (both of those can not be ES_KEEPSIZE!).
The width of the current control will always remain the same as in the dialog resource. ES_VCENTER works the same way, but for vertical centering (using top and bottom, and where the height will remain constant).
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
http://apps.hi.baidu.com/share/detail/30530119
这里需要解释的是宏EASYSIZE()的用法,其原型如下:
EASYSIZE(control,left,top,right,bottom,options)
该宏表示对ID值为control的控件实施缩放效果,缩放后的上下左右位置由control,left,top,right,bottom来确定,大小由option确定。
其中:control为对话框中的控件ID值,left,top,right,bottom四个参数为控件位置的坐标,其值可以选择ES_BOARD,ES_KEEPSIZE, 控件ID值三者之一。Options可以为ES_HCENTER, ES_VCENTER的结合,options可置0。
ES_BOARD表示控件与对话框边界(以下简称边界)的距离;
ES_KEEPSIZE表示控件水平/垂直方向上尺寸保持不变;
控件ID值表示当前控件与指定控件之间的距离;
ES_HCENTER表示缩放后控件在指定位置内水平居中;
ES_VCENTER表示缩放后控件在指定位置内垂直居中;
例如:
EASYSIZE(IDOK,ES_BORDER,ES_BORDER,ES_BORDER,ES_BORDER,0)
表示缩放后,值为IDOK的控件,距离边界上下左右位置保持不变,水平和垂直方向尺寸拉伸;
EASYSIZE(IDOK,ES_BORDER,ES_BORDER,ES_BORDER,ES_BORDER,ES_HCENTER)
表示缩放后,值为IDOK的控件,距离边界上下位置保持不变,垂直方向尺寸拉伸,水平居中;
EASYSIZE(IDOK,ES_BORDER,ES_BORDER,ES_BORDER,ES_BORDER,ES_HCENTER| ES_HCENTER)
表示缩放后,值为IDOK的控件,在对话框内垂直居中,水平居中;
EASYSIZE(IDOK,ES_BORDER,ES_KEEPSIZE,ES_KEEPSIZE,ES_BORDER,0)
表示缩放后,值为IDOK的控件,距离边界左、下方位置保持不变,同时保持控件尺寸;
EASYSIZE(IDOK,ES_BORDER,ES_KEEPSIZE, ES_BORDER,ES_BORDER,0)
表示缩放后,值为IDOK的控件,距离边界左、右、下方位置保持不变,水平方向尺寸拉伸,垂直方向尺寸不变;
EASYSIZE(IDOK,ES_BORDER,ES_BORDER,IDCANCEL,ES_BORDER,0)
表示缩放后,值为IDOK的控件,距离边界上下左位置保持不变,距离ID值为IDCANCEL的右方位置距离保持不变,水平和垂直方向尺寸拉伸;(当使用指定控件作为定位参数时候,确保指定控件的EASYSIZE在该宏前面)
相关文章推荐
- 使用Sublime Text 3作为Python编辑器有关中文问题
- Nginx设置浏览器本地缓存
- 高性能数据序列化库,可序列化为binary,也可序列化为json,支持C++ java python php objectc 语言,兼容json数据格试,可以互相转换,跨语言交换数据,网络传输,远程调
- Win32串口编程(转:韩耀旭)
- UML类图几种关系的总结
- Xcode自动注释插件
- 分桶法和平方分割
- IOS开发中如何判断程序第一次启动(根据判断结果决定是否显示新手操作引导)
- js学习笔记
- #1082 : 然而沼跃鱼早就看穿了一切
- SSH+Oracle10G抛Disabling contextual LOB creation as createClob() m
- c++ 时间和日期、随机数—— c++复习(四)
- Android中使用DownloadManager类来管理数据下载的教程
- Android获取图片,自动添加文字水印
- 点击弹出气泡注释,滚动条滚动隐藏气泡内容
- MyCat源码解析(1)
- Linux 下 /dev/zero 和 /dev/null
- javascript中的构造函数和继承
- 怎样禁止手机app 中页面有时候会把数字当做电话号码,从而自动进行打电话功能
- 团队冲刺站立会议10