zoukankan      html  css  js  c++  java
  • 【VS开发】EasySize使用设置CFormView空间自适应view窗口大小

    1、在stdafx.h中引用EasySize.h头文件(同时将EasySize.h放到你的程序目录中)

     

    2、在类定义中添加DECLARE_EASYSIZE

    1. class CEasySizeDemoDlg : public CDialog  
    2. {  
    3. DECLARE_EASYSIZE  
    4. ``````  
    5. };  

    3、增加OnInitDialog处理函数,将INIT_EASYSIZE放到函数尾处。

    1. BOOL CEasySizeDemoDlg::OnInitDialog()  
    2. {  
    3. `````     
    4.     INIT_EASYSIZE;  
    5. `````     
    6. }  



     

    4、增加OnSize函数,添加宏UPDATE_EASYSIZE

    1. void CEasySizeDemoDlg::OnSize(UINT nType, int cx, int cy)   
    2. {  
    3.     CDialog::OnSize(nType, cx, cy);  
    4.     UPDATE_EASYSIZE;  
    5. }  



     

    5、可选(最小化)

    6、创建EasySize映射(map),在此map里,你可以制定每个对话框的行为。它可以放在类实现文件的任何位置。

    BEGIN_EASYSIZE_MAP(class_name)

        ...

        EASYSIZE(control,left,top,right,bottom,options)

        ...

    END_EASYSIZE_MAP

    源码如下:

    1. BEGIN_EASYSIZE_MAP(CEasySizeDemoDlg)  
    2.     EASYSIZE(IDC_TITLE,ES_BORDER,ES_BORDER,ES_BORDER,ES_KEEPSIZE,ES_HCENTER)  
    3.     EASYSIZE(IDC_RADIO1,ES_BORDER,ES_BORDER,ES_KEEPSIZE,ES_KEEPSIZE,0)  
    4.     EASYSIZE(IDC_RADIO2,ES_BORDER,ES_BORDER,ES_KEEPSIZE,ES_KEEPSIZE,0)  
    5.     EASYSIZE(IDC_STATUSFRAME,ES_BORDER,ES_KEEPSIZE,ES_BORDER,ES_BORDER,0)  
    6.     EASYSIZE(IDC_STATUS,ES_BORDER,ES_KEEPSIZE,ES_BORDER,ES_BORDER,0)  
    7.     EASYSIZE(IDOK,ES_KEEPSIZE,ES_KEEPSIZE,ES_BORDER,ES_BORDER,0)  
    8.     EASYSIZE(IDCANCEL,ES_KEEPSIZE,ES_KEEPSIZE,ES_BORDER,ES_BORDER,0)  
    9.     EASYSIZE(IDC_MYICON2,ES_BORDER,ES_BORDER,IDC_TITLE,ES_KEEPSIZE,ES_HCENTER)  
    10.     EASYSIZE(IDC_CONTENT,IDC_TITLE,ES_BORDER,ES_BORDER,ES_BORDER,0)  
    11.     EASYSIZE(IDC_MIDFRAME,ES_BORDER,ES_BORDER,IDC_CONTENT,ES_BORDER,0)  
    12.     EASYSIZE(IDC_MIDRECT,ES_BORDER,ES_BORDER,IDC_CONTENT,ES_BORDER,0)  
    13.     EASYSIZE(IDC_MYICON1,IDC_MIDRECT,IDC_MIDRECT,IDC_MIDRECT,IDC_MIDRECT,ES_HCENTER|ES_VCENTER)  
    14. 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在该宏前面)

  • 相关阅读:
    再谈C#装箱和拆箱操作
    C#装箱与拆箱总结
    大话设计模式
    创建ASP.NET Webservice
    Lambada和linq查询数据库的比较
    设置VS2015背景图片(转载)
    windows 下使用Linux 子系统-安装.net core 环境
    .net core 3.1 ef Migrations 使用 CLI 数据迁移及同步
    linq 大数据 sql 查询及分页优化
    数据迁移最快方式,多线程并行执行 Sql插入
  • 原文地址:https://www.cnblogs.com/huty/p/8518695.html
Copyright © 2011-2022 走看看