CResizeCtrl

下载源文件- 7kbdownload演示项目- 30kbintroduction CResizeCtrl实现了WCL (Optima++别名的框架Power++,它被Sybase删除了)的ResizePercentage方法。 对于每个控件左侧、顶部、宽度和高度指定,以确定当父窗口的大小改变时,控件窗口的位置和大小将如何改变。 left指定对象的左边缘位置相对于父窗口宽度的总变化。 例如:假设左边是50,并且窗口的宽度增加了200像素,那么对象的左边缘向右移动了100像素(200的50%)。 top指定对象的顶部位置相对于父窗口高度的总变化。 例如:假设顶部是40,并且窗口的高度减少了20像素,那么对象的顶部边缘向上移动了8像素(20的40%)。 宽度指定对象的宽度相对于父窗口宽度的总变化。 例如:假设宽度为零。然后对象的宽度不会改变,无论父窗口的宽度改变了多少。 或者假设宽度为100,窗口的宽度减少了50个像素,那么对象的宽度也减少了50个像素(100%为50)。 高度指定对象的高度相对于父窗口高度的总变化。 例如:假设高度为20,父窗口的高度减少了50个像素,那么对象的高度也减少了10个像素(50的20%)。 每个参数的有效范围是0到maxPart,但是left + width和top + height的和必须小于或等于maxPart 一般采用以下公式 隐藏,复制Code

newValue = oldValue + (( deltaValueParent * partValue) / maxPart )

地点: newValue是新的左边或顶部位置或新的宽度或高值是旧的左边或顶部位置或旧的宽度或高值父母的宽度或高度的变化 partvalue是添加方法中指定的左、上、宽或高的值。maxpartis是由构造函数或创建方法的maxPart参数指定的值 maxPart的默认值是100,为了更好的粒度,可以在构造函数或创建方法中指定另一个值 例子: 隐藏,复制Code

// Create the control
m_resize.Create( this );
// Add the controls to be resized
//                         l    t    w    h
m_resize.Add( IDC_EDIT1,   0,   0, 100,  50 );
m_resize.Add( IDC_LIST1,   0,  50, 100,  50 );
m_resize.Add( IDOK,       50, 100,   0,   0 );
// Use the current width and height 
// for minimum tracking size
m_resize.SetMinimumTrackingSize();

当父窗口的宽度增加了40像素,高度增加了20像素时: 隐藏,复制Code

IDC_EDIT1: left +=  0 top +=  0 width += 40 height += 10
IDC_LIST1: left +=  0 top += 10 width += 40 height += 10
IDOK     : left += 20 top += 20 width +=  0 height +=  0

用法: 添加文件ResizeCtrl。cpp’和‘ResizeCtrl。支持你的项目 因为CResizeCtrl可以更改对话框的样式,所以没有必要在对话框模板中添加可调整大小的边框。 包括“ResizeCtrl。并将CResizeCtrl添加到您的对话框类的实例数据中 隐藏,复制Code

#include "ResizeCtrl.h"

class CDemoDialog : public CDialog
{
  // other stuff
  CResizeCtrl m_resize;
  //....

在OnInitDialog中添加应该调整为CResizeCtrl对象大小的控件 隐藏,复制Code

BOOL CDemoDialog::OnInitDialog()
{
  CDialog::OnInitDialog();
    
  // TODO: Add extra initialization here
  // Create the control
  m_resize.Create( this );
  // Add the controls to be resized
  //                         l    t    w    h
  m_resize.Add( IDC_EDIT1,   0,   0, 100,  50 );
  m_resize.Add( IDC_LIST1,   0,  50, 100,  50 );
  m_resize.Add( IDOK,       50, 100,   0,   0 );
  // Use the current width and height 
  // for minimum tracking size
  m_resize.SetMinimumTrackingSize();

或 隐藏,复制Code

BOOL CDemoDialog::OnInitDialog()
{
  CDialog::OnInitDialog();
    
  // TODO: Add extra initialization here
  // Create the control
  m_resize.Create( this );
  // Add the controls to be resized
  CResizeInfo rInfo[] =
  {
    //  id         l    t    w    h
    { IDC_EDIT1,   0,   0, 100,  50 },
    { IDC_LIST1,   0,  50, 100,  50 },
    { IDOK,       50, 100,   0,   0 },
    { 0 },
  };
  m_resize.Add( rInfo );
  // Use the current width and height 
  // for minimum tracking size
  m_resize.SetMinimumTrackingSize();

因为CResizeCtrl不是来自CDialog的派生类,所以可以在不更改对话框模板的情况下使用它。 它甚至可以与通用控件一起使用。演示项目包括一个示例,如何使用它与GetOpenFileName。 本文转载于:http://www.diyabc.com/frontweb/news5101.html

原文地址:https://www.cnblogs.com/Dincat/p/13462293.html