MFC界面控件位置大小控制的EasySize使用说明
来源:互联网 发布:外盘期货数据接口 编辑:程序博客网 时间:2024/05/01 13:20
第二步:在对话框类定义下面添加"DECLARE_EASYSIZE"宏,没有分号,同消息映射类似。
第三步:添加控件布局映射,在该对话实现文件的消息映射下加上:BEGIN_EASYSIZE_MAP(对话框类名)
EASYSIZE(控件ID,left,top,right,bottom,options);
END_EASYSIZE_MAP,该格式类似消息映射的格式
第四步:在对话框的onInitDialog里添加宏:"INIT_EASYSIZE;",该句是有分号的。
第五步:在对话框的OnSize里添加宏:"UPDATE_EASYSIZE;",该句是有分号的。
第六步:如果要限制对话框的最小尺寸,在对话框的OnSizing里添加:EASYSIZE_MINSIZE
(width,height,fwSide,pRect);
注意:1、第二步和第三步必须对应,不然连接会报错。
2、一般Dialog没有WM_SIZING,在Class Wizard里选择Class Info标签,然后在Message Fileter下拉列表中选
择Windows,然后再点击Message Maps标签,就出现WM_SIZING消息了。
3、control是要设置的控件的ID;left、top、right、bottom分别指的是该控件左、上、右、下方的控件的ID,
也可以为以下特殊值;ES_BORDER:保持与边框距离不变;ES_KEEPSIZE:保持大小不变;options可指定为0,也
可指定为以下值:ES_HCENTER:保持宽度不变,水平位置在left和right指定的控件正中间;ES_VCENTER:保持
高度不变,垂直位置在left和right指定的控件正中间。
EasySize.h文件内容
/*===================================================*\
| |
| EASY-SIZE Macros |
| |
| Copyright (c) 2001 - Marc Richarme |
| devix@devix.cjb.net |
| http://devix.cjb.net |
| |
| License: |
| |
| You may use this code in any commersial or non- |
| commersial application, and you may redistribute |
| this file (and even modify it if you wish) as |
| long as you keep this notice untouched in any |
| version you redistribute. |
| |
| Usage: |
| |
| - Insert 'DECLARE_EASYSIZE' somewhere in your |
| class declaration |
| - Insert an easysize map in the beginning of your |
| class implementation (see documentation) and |
| outside of any function. |
| - Insert 'INIT_EASYSIZE;' in your |
| OnInitDialog handler. |
| - Insert 'UPDATE_EASYSIZE' in your OnSize handler |
| - Optional: Insert 'EASYSIZE_MINSIZE(mx,my);' in |
| your OnSizing handler if you want to specify |
| a minimum size for your dialog |
| |
| Check http://devix.cjb.net for the |
| docs and new versions |
| |
\*===================================================*/
#ifndef __EASYSIZE_H_
#define __EASYSIZE_H_
#define ES_BORDER 0xffffffff
#define ES_KEEPSIZE 0xfffffffe
#define ES_HCENTER 0x00000001
#define ES_VCENTER 0x00000002
#define DECLARE_EASYSIZE \
void __ES__RepositionControls(BOOL bInit);\
void __ES__CalcBottomRight(CWnd *pThis, BOOL bBottom, int &bottomright, int &topleft, UINT id, UINT br, int es_br, CRect &rect, int clientbottomright);
#define INIT_EASYSIZE __ES__RepositionControls(TRUE); __ES__RepositionControls(FALSE)
#define UPDATE_EASYSIZE if(GetWindow(GW_CHILD)!=NULL) __ES__RepositionControls(FALSE)
#define EASYSIZE_MINSIZE(mx,my,s,r) if(r->right-r->left < mx) { if((s == WMSZ_BOTTOMLEFT)||(s == WMSZ_LEFT)||(s == WMSZ_TOPLEFT)) r->left = r->right-mx; else r->right = r->left+mx; } if(r->bottom-r->top < my) { if((s == WMSZ_TOP)||(s == WMSZ_TOPLEFT)||(s == WMSZ_TOPRIGHT)) r->top = r->bottom-my; else r->bottom = r->top+my; }
#define BEGIN_EASYSIZE_MAP(class) \
void class::__ES__CalcBottomRight(CWnd *pThis, BOOL bBottom, int &bottomright, int &topleft, UINT id, UINT br, int es_br, CRect &rect, int clientbottomright) {\
if(br==ES_BORDER) bottomright = clientbottomright-es_br;\
else if(br==ES_KEEPSIZE) bottomright = topleft+es_br;\
else { CRect rect2;\
pThis->GetDlgItem(br)->GetWindowRect(rect2); pThis->ScreenToClient(rect2);\
bottomright = (bBottom?rect2.top:rect2.left) - es_br;}}\
void class::__ES__RepositionControls(BOOL bInit) { CRect rect,rect2,client; GetClientRect(client);
#define END_EASYSIZE_MAP Invalidate(); UpdateWindow(); }
#define EASYSIZE(id,l,t,r,b,o) \
static int id##_es_l, id##_es_t, id##_es_r, id##_es_b;\
if(bInit) {\
GetDlgItem(id)->GetWindowRect(rect); ScreenToClient(rect);\
if(o & ES_HCENTER) id##_es_l = rect.Width()/2; else {\
if(l==ES_BORDER) id##_es_l = rect.left; else if(l==ES_KEEPSIZE) id##_es_l = rect.Width(); else {\
GetDlgItem(l)->GetWindowRect(rect2); ScreenToClient(rect2);\
id##_es_l = rect.left-rect2.right;}}\
if(o & ES_VCENTER) id##_es_t = rect.Height()/2; else {\
if(t==ES_BORDER) id##_es_t = rect.top; else if(t==ES_KEEPSIZE) id##_es_t = rect.Height(); else {\
GetDlgItem(t)->GetWindowRect(rect2); ScreenToClient(rect2);\
id##_es_t = rect.top-rect2.bottom;}}\
if(o & ES_HCENTER) id##_es_r = rect.Width(); else { if(r==ES_BORDER) id##_es_r = client.right-rect.right; else if(r==ES_KEEPSIZE) id##_es_r = rect.Width(); else {\
GetDlgItem(r)->GetWindowRect(rect2); ScreenToClient(rect2);\
id##_es_r = rect2.left-rect.right;}}\
if(o & ES_VCENTER) id##_es_b = rect.Height(); else { if(b==ES_BORDER) id##_es_b = client.bottom-rect.bottom; else if(b==ES_KEEPSIZE) id##_es_b = rect.Height(); else {\
GetDlgItem(b)->GetWindowRect(rect2); ScreenToClient(rect2);\
id##_es_b = rect2.top-rect.bottom;}}\
} else {\
int left,top,right,bottom; BOOL bR = FALSE,bB = FALSE;\
if(o & ES_HCENTER) { int _a,_b;\
if(l==ES_BORDER) _a = client.left; else { GetDlgItem(l)->GetWindowRect(rect2); ScreenToClient(rect2); _a = rect2.right; }\
if(r==ES_BORDER) _b = client.right; else { GetDlgItem(r)->GetWindowRect(rect2); ScreenToClient(rect2); _b = rect2.left; }\
left = _a+((_b-_a)/2-id##_es_l); right = left + id##_es_r;} else {\
if(l==ES_BORDER) left = id##_es_l;\
else if(l==ES_KEEPSIZE) { __ES__CalcBottomRight(this,FALSE,right,left,id,r,id##_es_r,rect,client.right); left = right-id##_es_l;\
} else { GetDlgItem(l)->GetWindowRect(rect2); ScreenToClient(rect2); left = rect2.right + id##_es_l; }\
if(l != ES_KEEPSIZE) __ES__CalcBottomRight(this,FALSE,right,left,id,r,id##_es_r,rect,client.right);}\
if(o & ES_VCENTER) { int _a,_b;\
if(t==ES_BORDER) _a = client.top; else { GetDlgItem(t)->GetWindowRect(rect2); ScreenToClient(rect2); _a = rect2.bottom; }\
if(b==ES_BORDER) _b = client.bottom; else { GetDlgItem(b)->GetWindowRect(rect2); ScreenToClient(rect2); _b = rect2.top; }\
top = _a+((_b-_a)/2-id##_es_t); bottom = top + id##_es_b;} else {\
if(t==ES_BORDER) top = id##_es_t;\
else if(t==ES_KEEPSIZE) { __ES__CalcBottomRight(this,TRUE,bottom,top,id,b,id##_es_b,rect,client.bottom); top = bottom-id##_es_t;\
} else { GetDlgItem(t)->GetWindowRect(rect2); ScreenToClient(rect2); top = rect2.bottom + id##_es_t; }\
if(t != ES_KEEPSIZE) __ES__CalcBottomRight(this,TRUE,bottom,top,id,b,id##_es_b,rect,client.bottom);}\
GetDlgItem(id)->MoveWindow(left,top,right-left,bottom-top,FALSE);\
}
#endif //__EASYSIZE_H_
- MFC界面控件位置大小控制的EasySize使用说明
- MFC 界面部件大小位置自适应 EasySize的使用
- easysize的使用方法 (实现控件大小位置随界面变化而有相应的变化,这个变化可以自己设置)
- 【转】关于EASYSIZE宏(动态调整控件位置、大小的宏)的小结
- 【转】关于EASYSIZE宏(动态调整控件位置、大小的宏)的小结
- 【转】关于EASYSIZE宏(动态调整控件位置、大小的宏)的小结
- 【转】关于EASYSIZE宏(动态调整控件位置、大小的宏)的小结
- EasySize动态调整对话框控件位置和大小
- android 控制控件的位置和大小
- android 控制控件的位置和大小
- 精确控制MFC控件窗口的位置和大小(top|left|width|height)
- 小猫统计定制CRUD(增查删改)界面:界面内元素(控件)的位置移动、大小控制
- EasySize类-----改变窗口中各个控件的大小
- MFC中改变控件的大小和位置(zz)
- MFC中改变控件的大小和位置 晕
- MFC中控件的大小和位置自定义代码
- MFC中改变控件的大小和位置
- MFC怎么设置控件的位置和大小
- javascript运行机制之执行顺序详解
- 海量数据的处理(转)
- 【VS开发】使用MFC创建并调用ActiveX控件
- Hello Python
- Pots
- MFC界面控件位置大小控制的EasySize使用说明
- 分布式爬虫:使用Scrapy抓取数据
- web页面抽取结构五元组的序列划分生成
- Java线程池的实现原理
- Codeforces Round #364(Div. 2) A. Cards【模拟】 && B. Cells Not Under Attack【SET/规律】
- SAP Hybris电子商务最新功能
- 项目中有关a标签和onclick之间的执行关系
- STM32以太网程序解析
- SDUT 2482 二叉排序树