自动改变控件位置和大小

时间:2021-12-10 14:47:24
刚才在网上找到一个号称可以自动改变控件位置和大小的对话框的类ClxDialog,但是调试了半天也没有成功.
控件挺多一个一个调位置有点恐怖.
寻一份可用的代码或者源程序,谢谢!
可以发我邮箱shaosjm@163.com

10 个解决方案

#1


在EnumChildWindow 里面调整就行了。

#2


控件也是可以枚举的,::GetWindow()

#3


ClxDialog
这个类是可以调整大小的,如果不能那是你自己没有好好看如何使用它。

参看下面文章:
http://www.joyvc.cn/GuiAndWindows/GuiAndWindows00040.html
http://www.joyvc.cn/GuiAndWindows/GuiAndWindows00044.html

#4


引用 2 楼 zhoujianhei 的回复:
控件也是可以枚举的,::GetWindow() 


没错

#5


学习,顶。

#6


GetWindow、FindWindowEx、EnumChildWindows都可以遍历所有控件。

#7


http://blog.csdn.net/zzz3265/archive/2008/08/31/2854642.aspx

AddItem 设置每个控件的 x, y, w, h 百分比
OnSize的时候自动改变

#8


给你一个CResizeDialog的类,我按照网上的资料自己整理的。
头文件:ResizeDialog.h
#if !defined(AFX_RESIZEDIALOG_H__4220AE11_16FC_4401_BDB1_D81058824816__INCLUDED_)
#define AFX_RESIZEDIALOG_H__4220AE11_16FC_4401_BDB1_D81058824816__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// ResizeDialog.h : header file
//

/////////////////////////////////////////////////////////////////////////////
// CResizeDialog dialog

class CResizeDialog : public CDialog
{
// Construction
public:
CResizeDialog(CWnd* pParent = NULL);   // standard constructor

// Dialog Data
//{{AFX_DATA(CResizeDialog)
enum { IDD = IDD_DIALOG_MAPPING };
// NOTE: the ClassWizard will add data members here
//}}AFX_DATA

typedef struct _dlgControlTag 
    {
        int iId;
        int iFlag;
        int iPercent;
    } DLGCTLINFO, *PDLGCTLINFO;

    enum
    {
        MOVEX = 0,
        MOVEY,
        MOVEXY,
        ELASTICX,
        ELASTICY,
        ELASTICXY
    };

    //  设置控件信息
    BOOL SetControlProperty(PDLGCTLINFO lp, int nElements);

    //  是否在对话框右下角显示表示可改变大小的图标
    void ShowSizeIcon(BOOL bShow = TRUE);

protected:
    virtual BOOL OnInitDialog();
    afx_msg void OnSize(UINT nType, int cx, int cy);
    afx_msg void OnSizing(UINT nSide, LPRECT lpRect);
    DECLARE_MESSAGE_MAP()

private:
    int m_iClientWidth;  //  对话框client区域的宽度
    int m_iClientHeight;  //  对话框client区域的高度
    int m_iMinWidth;  //  对话框的最小宽度
    int m_iMinHeight;  //  对话框的最小高度
    PDLGCTLINFO m_pControlArray;  //  控件信息数组指针
    int m_iControlNumber;  //  设置控件信息的控件个数
    BOOL m_bShowSizeIcon;  //  是否显示表示可改变大小的图标
    CStatic m_wndSizeIcon;  //  放图标的静态控件
    //  保存图标的bitmap
    CBitmap m_bmpSizeIcon; 
    BITMAP m_bitmap;

// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CResizeDialog)
protected:
virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
//}}AFX_VIRTUAL

// Implementation
protected:

// Generated message map functions
//{{AFX_MSG(CResizeDialog)
// afx_msg void OnSize(UINT nType, int cx, int cy);
// virtual BOOL OnInitDialog();
//}}AFX_MSG
// DECLARE_MESSAGE_MAP()
};

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_RESIZEDIALOG_H__4220AE11_16FC_4401_BDB1_D81058824816__INCLUDED_)

#9


源文件:ResizeDialog.cpp
// ResizeDialog.cpp : implementation file
//

#include "stdafx.h"
#include "ShowMapping.h"
#include "ResizeDialog.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

//  表示可改变大小的图标ID
#ifndef OBM_SIZE
#define OBM_SIZE 32766
#endif

/////////////////////////////////////////////////////////////////////////////
// CResizeDialog dialog


CResizeDialog::CResizeDialog(CWnd* pParent /*=NULL*/)
: CDialog(CResizeDialog::IDD, pParent)
, m_iClientWidth(0)
    , m_iClientHeight(0)
    , m_iMinWidth(0)
    , m_iMinHeight(0)
    , m_pControlArray(NULL)
    , m_iControlNumber(0)
    , m_bShowSizeIcon(TRUE)
{
//{{AFX_DATA_INIT(CResizeDialog)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}


void CResizeDialog::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CResizeDialog)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CResizeDialog, CDialog)
//{{AFX_MSG_MAP(CResizeDialog)
ON_WM_SIZE()
ON_WM_SIZING()
//}}AFX_MSG_MAP
// ON_WM_SIZE()
 //   

END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CResizeDialog message handlers

void CResizeDialog::OnSize(UINT nType, int cx, int cy) 
{
CDialog::OnSize(nType, cx, cy);

// TODO: Add your message handler code here
//  对话框宽度和高度的增量 
    int iIncrementX = cx - m_iClientWidth;
    int iIncrementY = cy - m_iClientHeight;

    //  最小化时增量为0
    if (nType == SIZE_MINIMIZED)
    {
        iIncrementX = iIncrementY = 0;
    }

    for (int i = 0; i < m_iControlNumber; i++)
    {
        CWnd *pWndCtrl = NULL;

        int iId = m_pControlArray[i].iId;
        int iFlag = m_pControlArray[i].iFlag;
        int iPercent = m_pControlArray[i].iPercent;

        //  无效值
        if ((iPercent < 0) || (iPercent > 100))
            continue;

        //  得到控件指针
        pWndCtrl = GetDlgItem(iId);
        if ((NULL != pWndCtrl) && IsWindow(pWndCtrl->GetSafeHwnd()))
        {
            CRect rectCtrl;
            pWndCtrl->GetWindowRect(rectCtrl);

            ScreenToClient(rectCtrl);

            int iLeft = rectCtrl.left;
            int iTop = rectCtrl.top;
            int iWidth = rectCtrl.Width();
            int iHeight = rectCtrl.Height();

            switch (iFlag)
            {
            case MOVEX:  //  X方向移动
                iLeft += (iIncrementX * iPercent / 100);
                break;

            case MOVEY:  //  Y方向移动
                iTop += (iIncrementY * iPercent / 100);
                break;

            case MOVEXY:  //  X方向和Y方向同时移动
                iLeft += (iIncrementX * iPercent / 100);
                iTop += (iIncrementY * iPercent / 100);
                break;

            case ELASTICX:  //  X方向改变大小
                iWidth += (iIncrementX * iPercent / 100);
                break;

            case ELASTICY:  //  Y方向改变大小
                iHeight += (iIncrementY * iPercent / 100);
                break;

            case ELASTICXY:  //  X方向和Y方向同时改变大小
                iWidth += (iIncrementX * iPercent / 100);
                iHeight += (iIncrementY * iPercent / 100);
                break;

            default:
                ;
            }

            //  把控件移动到新位置
            pWndCtrl->MoveWindow(iLeft, iTop, iWidth, iHeight);
            }
    }

    //  把图标移动到对话框右下角
    if (IsWindow(m_wndSizeIcon.GetSafeHwnd()))
    {
        m_wndSizeIcon.MoveWindow(cx - m_bitmap.bmWidth, cy - m_bitmap.bmHeight, m_bitmap.bmWidth, m_bitmap.bmHeight);

        if (nType == SIZE_MAXIMIZED)
             m_wndSizeIcon.ShowWindow(FALSE);
        else
            m_wndSizeIcon.ShowWindow(TRUE);
    }

    Invalidate();

    //  记录对话框client区域的大小
    if (nType != SIZE_MINIMIZED)
    {
        m_iClientWidth = cx;
        m_iClientHeight = cy;
    }
}

BOOL CResizeDialog::OnInitDialog() 
{
CDialog::OnInitDialog();

// TODO: Add extra initialization here
//  设置对话框为可变大小的
    ModifyStyle(0, WS_SIZEBOX);

    //  以对话框的初始大小作为对话框的宽度和高度的最小值
    CRect rectDlg;
    GetWindowRect(rectDlg);
    m_iMinWidth = rectDlg.Width();
    m_iMinHeight = rectDlg.Height();

    //  得到对话框client区域的大小
    CRect rectClient;
    GetClientRect(rectClient);
    m_iClientWidth = rectClient.Width();
    m_iClientHeight = rectClient.Height();

    //  Load图标
    m_bmpSizeIcon.LoadOEMBitmap(OBM_SIZE);
    m_bmpSizeIcon.GetBitmap(&m_bitmap);

    //  创建显示图标的静态控件并放在对话框右下角
    m_wndSizeIcon.Create(NULL, WS_CHILD | WS_VISIBLE | SS_BITMAP, CRect(0, 0, m_bitmap.bmWidth, m_bitmap.bmHeight), this, 0);
    m_wndSizeIcon.SetBitmap(m_bmpSizeIcon);
    m_wndSizeIcon.MoveWindow(m_iClientWidth - m_bitmap.bmWidth, m_iClientHeight - m_bitmap.bmHeight, m_bitmap.bmWidth, m_bitmap.bmHeight);

    //  显示图标
    m_wndSizeIcon.ShowWindow(m_bShowSizeIcon);

return TRUE;  // return TRUE unless you set the focus to a control
              // EXCEPTION: OCX Property Pages should return FALSE
}

void CResizeDialog::OnSizing(UINT nSide, LPRECT lpRect)
{
    CDialog::OnSizing(nSide, lpRect);

    //  对话框不能小于初始大小

    int iWidth = lpRect->right - lpRect->left;
    int iHeight = lpRect->bottom - lpRect->top;

    if (iWidth <= m_iMinWidth)
        lpRect->right = lpRect->left + m_iMinWidth;
  
    if(iHeight <= m_iMinHeight)
        lpRect->bottom = lpRect->top + m_iMinHeight;
}

BOOL CResizeDialog::SetControlProperty(PDLGCTLINFO lp, int nElements)
{
    //  设置控件数组信息

    if (NULL == lp)
        return FALSE;

    if (nElements <= 0)
        return FALSE;

    m_pControlArray = lp;
    m_iControlNumber = nElements;

    return TRUE;
}

void CResizeDialog::ShowSizeIcon(BOOL bShow /*=TRUE*/)
{
    m_bShowSizeIcon = bShow;
}

#10


对了哈,刚才贴的源文件中有一个#include "ShowMapping.h"这个东东可以去掉的哈,是我自己的一个程序,需要用到CResizeDialog这个类的。
使用这个类时注意的问题:
1.在需要resize的Dialog里#include "ResizeDialog.h"
2.将需要resize的Dialog属性设置为Resizing.
3.将需要resize的Dialog的类里边所有CDialog替换为CResizeDialog;
4.在需要resize的Dialog的OnInitDialog()函数里添加下面类似的代码就OK了:
//  控件信息数组
static DLGCTLINFO  dcMenuGroup[] = 
{
{IDOK, MOVEXY, 50},
{IDCANCEL, MOVEXY, 50},
{IDC_VERSION,MOVEXY,100},
{IDC_MAP,MOVEY,50},
{IDC_SCROLLBAR_ROW,MOVEY,50},
{IDC_SCROLLBAR_COL,MOVEX,50},
{IDC_MAGNIFIER,MOVEXY,50},
{IDC_GROUP1,ELASTICX,50},
{IDC_GROUP2,ELASTICX,50},
{IDC_GROUP2,MOVEY,50},
{IDC_EDIT_DATAPATH,ELASTICX,50},
{IDC_EDIT_LOTID,ELASTICX,50},
{IDC_EDIT_DEVICE,ELASTICX,50},
{IDC_EDIT_TESTERID,ELASTICX,50},
{IDC_EDIT_TESTERID,MOVEY,50},
{IDC_EDIT_PCID,ELASTICX,50},
{IDC_EDIT_PCID,MOVEY,50},
{IDC_EDIT_STARTTIME,ELASTICX,50},
{IDC_EDIT_STARTTIME,MOVEY,50},
{IDC_EDIT_ENDTIME,ELASTICX,50},
{IDC_EDIT_ENDTIME,MOVEY,50},
{IDC_EDIT_PASS,ELASTICX,50},
{IDC_EDIT_PASS,MOVEY,50},
{IDC_EDIT_TOTAL,ELASTICX,50},
{IDC_EDIT_TOTAL,MOVEY,50},
{IDC_EDIT_YIELD,ELASTICX,50},
{IDC_EDIT_YIELD,MOVEY,50},
{IDC_LIST_RAWDATA,ELASTICXY,50},
{IDC_LIST_BINPERCENT,ELASTICXY,50},
{IDC_LIST_BINPERCENT,MOVEY,50},
{IDC_BTN_MAPBINSELECT,MOVEXY,50},
{IDC_BTN_MAPSETTING,MOVEXY,50},
{IDC_BTN_MAPSTYLE,MOVEXY,50},
{IDC_BTN_SAVE,MOVEXY,50},
{IDC_BTN_MAG,MOVEXY,50},
{IDC_BTN_QUERY,MOVEXY,50},
{IDC_STATIC_YIELD,MOVEY,50},
{IDC_STATIC_TOTAL,MOVEY,50},
{IDC_STATIC_PASS,MOVEY,50},
{IDC_STATIC_ENDTIME,MOVEY,50},
{IDC_STATIC_STARTTIME,MOVEY,50},
{IDC_STATIC_PCID,MOVEY,50},
{IDC_STATIC_TESTERID,MOVEY,50},
{IDC_STATIC_X,MOVEY,50},
{IDC_STATIC_Y,MOVEY,50},
{IDC_EDIT_X,ELASTICX,50},
{IDC_EDIT_X,MOVEY,50},
{IDC_EDIT_Y,ELASTICX,50},
{IDC_EDIT_Y,MOVEY,50},
{IDC_STATIC_NOTCH,MOVEY,50},
{IDC_EDIT_NOTCH,ELASTICX,50},
{IDC_EDIT_NOTCH,MOVEY,50},
};
//  设置控件信息
SetControlProperty(dcMenuGroup, sizeof(dcMenuGroup)/sizeof(DLGCTLINFO));

#1


在EnumChildWindow 里面调整就行了。

#2


控件也是可以枚举的,::GetWindow()

#3


ClxDialog
这个类是可以调整大小的,如果不能那是你自己没有好好看如何使用它。

参看下面文章:
http://www.joyvc.cn/GuiAndWindows/GuiAndWindows00040.html
http://www.joyvc.cn/GuiAndWindows/GuiAndWindows00044.html

#4


引用 2 楼 zhoujianhei 的回复:
控件也是可以枚举的,::GetWindow() 


没错

#5


学习,顶。

#6


GetWindow、FindWindowEx、EnumChildWindows都可以遍历所有控件。

#7


http://blog.csdn.net/zzz3265/archive/2008/08/31/2854642.aspx

AddItem 设置每个控件的 x, y, w, h 百分比
OnSize的时候自动改变

#8


给你一个CResizeDialog的类,我按照网上的资料自己整理的。
头文件:ResizeDialog.h
#if !defined(AFX_RESIZEDIALOG_H__4220AE11_16FC_4401_BDB1_D81058824816__INCLUDED_)
#define AFX_RESIZEDIALOG_H__4220AE11_16FC_4401_BDB1_D81058824816__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// ResizeDialog.h : header file
//

/////////////////////////////////////////////////////////////////////////////
// CResizeDialog dialog

class CResizeDialog : public CDialog
{
// Construction
public:
CResizeDialog(CWnd* pParent = NULL);   // standard constructor

// Dialog Data
//{{AFX_DATA(CResizeDialog)
enum { IDD = IDD_DIALOG_MAPPING };
// NOTE: the ClassWizard will add data members here
//}}AFX_DATA

typedef struct _dlgControlTag 
    {
        int iId;
        int iFlag;
        int iPercent;
    } DLGCTLINFO, *PDLGCTLINFO;

    enum
    {
        MOVEX = 0,
        MOVEY,
        MOVEXY,
        ELASTICX,
        ELASTICY,
        ELASTICXY
    };

    //  设置控件信息
    BOOL SetControlProperty(PDLGCTLINFO lp, int nElements);

    //  是否在对话框右下角显示表示可改变大小的图标
    void ShowSizeIcon(BOOL bShow = TRUE);

protected:
    virtual BOOL OnInitDialog();
    afx_msg void OnSize(UINT nType, int cx, int cy);
    afx_msg void OnSizing(UINT nSide, LPRECT lpRect);
    DECLARE_MESSAGE_MAP()

private:
    int m_iClientWidth;  //  对话框client区域的宽度
    int m_iClientHeight;  //  对话框client区域的高度
    int m_iMinWidth;  //  对话框的最小宽度
    int m_iMinHeight;  //  对话框的最小高度
    PDLGCTLINFO m_pControlArray;  //  控件信息数组指针
    int m_iControlNumber;  //  设置控件信息的控件个数
    BOOL m_bShowSizeIcon;  //  是否显示表示可改变大小的图标
    CStatic m_wndSizeIcon;  //  放图标的静态控件
    //  保存图标的bitmap
    CBitmap m_bmpSizeIcon; 
    BITMAP m_bitmap;

// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CResizeDialog)
protected:
virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
//}}AFX_VIRTUAL

// Implementation
protected:

// Generated message map functions
//{{AFX_MSG(CResizeDialog)
// afx_msg void OnSize(UINT nType, int cx, int cy);
// virtual BOOL OnInitDialog();
//}}AFX_MSG
// DECLARE_MESSAGE_MAP()
};

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_RESIZEDIALOG_H__4220AE11_16FC_4401_BDB1_D81058824816__INCLUDED_)

#9


源文件:ResizeDialog.cpp
// ResizeDialog.cpp : implementation file
//

#include "stdafx.h"
#include "ShowMapping.h"
#include "ResizeDialog.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

//  表示可改变大小的图标ID
#ifndef OBM_SIZE
#define OBM_SIZE 32766
#endif

/////////////////////////////////////////////////////////////////////////////
// CResizeDialog dialog


CResizeDialog::CResizeDialog(CWnd* pParent /*=NULL*/)
: CDialog(CResizeDialog::IDD, pParent)
, m_iClientWidth(0)
    , m_iClientHeight(0)
    , m_iMinWidth(0)
    , m_iMinHeight(0)
    , m_pControlArray(NULL)
    , m_iControlNumber(0)
    , m_bShowSizeIcon(TRUE)
{
//{{AFX_DATA_INIT(CResizeDialog)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}


void CResizeDialog::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CResizeDialog)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CResizeDialog, CDialog)
//{{AFX_MSG_MAP(CResizeDialog)
ON_WM_SIZE()
ON_WM_SIZING()
//}}AFX_MSG_MAP
// ON_WM_SIZE()
 //   

END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CResizeDialog message handlers

void CResizeDialog::OnSize(UINT nType, int cx, int cy) 
{
CDialog::OnSize(nType, cx, cy);

// TODO: Add your message handler code here
//  对话框宽度和高度的增量 
    int iIncrementX = cx - m_iClientWidth;
    int iIncrementY = cy - m_iClientHeight;

    //  最小化时增量为0
    if (nType == SIZE_MINIMIZED)
    {
        iIncrementX = iIncrementY = 0;
    }

    for (int i = 0; i < m_iControlNumber; i++)
    {
        CWnd *pWndCtrl = NULL;

        int iId = m_pControlArray[i].iId;
        int iFlag = m_pControlArray[i].iFlag;
        int iPercent = m_pControlArray[i].iPercent;

        //  无效值
        if ((iPercent < 0) || (iPercent > 100))
            continue;

        //  得到控件指针
        pWndCtrl = GetDlgItem(iId);
        if ((NULL != pWndCtrl) && IsWindow(pWndCtrl->GetSafeHwnd()))
        {
            CRect rectCtrl;
            pWndCtrl->GetWindowRect(rectCtrl);

            ScreenToClient(rectCtrl);

            int iLeft = rectCtrl.left;
            int iTop = rectCtrl.top;
            int iWidth = rectCtrl.Width();
            int iHeight = rectCtrl.Height();

            switch (iFlag)
            {
            case MOVEX:  //  X方向移动
                iLeft += (iIncrementX * iPercent / 100);
                break;

            case MOVEY:  //  Y方向移动
                iTop += (iIncrementY * iPercent / 100);
                break;

            case MOVEXY:  //  X方向和Y方向同时移动
                iLeft += (iIncrementX * iPercent / 100);
                iTop += (iIncrementY * iPercent / 100);
                break;

            case ELASTICX:  //  X方向改变大小
                iWidth += (iIncrementX * iPercent / 100);
                break;

            case ELASTICY:  //  Y方向改变大小
                iHeight += (iIncrementY * iPercent / 100);
                break;

            case ELASTICXY:  //  X方向和Y方向同时改变大小
                iWidth += (iIncrementX * iPercent / 100);
                iHeight += (iIncrementY * iPercent / 100);
                break;

            default:
                ;
            }

            //  把控件移动到新位置
            pWndCtrl->MoveWindow(iLeft, iTop, iWidth, iHeight);
            }
    }

    //  把图标移动到对话框右下角
    if (IsWindow(m_wndSizeIcon.GetSafeHwnd()))
    {
        m_wndSizeIcon.MoveWindow(cx - m_bitmap.bmWidth, cy - m_bitmap.bmHeight, m_bitmap.bmWidth, m_bitmap.bmHeight);

        if (nType == SIZE_MAXIMIZED)
             m_wndSizeIcon.ShowWindow(FALSE);
        else
            m_wndSizeIcon.ShowWindow(TRUE);
    }

    Invalidate();

    //  记录对话框client区域的大小
    if (nType != SIZE_MINIMIZED)
    {
        m_iClientWidth = cx;
        m_iClientHeight = cy;
    }
}

BOOL CResizeDialog::OnInitDialog() 
{
CDialog::OnInitDialog();

// TODO: Add extra initialization here
//  设置对话框为可变大小的
    ModifyStyle(0, WS_SIZEBOX);

    //  以对话框的初始大小作为对话框的宽度和高度的最小值
    CRect rectDlg;
    GetWindowRect(rectDlg);
    m_iMinWidth = rectDlg.Width();
    m_iMinHeight = rectDlg.Height();

    //  得到对话框client区域的大小
    CRect rectClient;
    GetClientRect(rectClient);
    m_iClientWidth = rectClient.Width();
    m_iClientHeight = rectClient.Height();

    //  Load图标
    m_bmpSizeIcon.LoadOEMBitmap(OBM_SIZE);
    m_bmpSizeIcon.GetBitmap(&m_bitmap);

    //  创建显示图标的静态控件并放在对话框右下角
    m_wndSizeIcon.Create(NULL, WS_CHILD | WS_VISIBLE | SS_BITMAP, CRect(0, 0, m_bitmap.bmWidth, m_bitmap.bmHeight), this, 0);
    m_wndSizeIcon.SetBitmap(m_bmpSizeIcon);
    m_wndSizeIcon.MoveWindow(m_iClientWidth - m_bitmap.bmWidth, m_iClientHeight - m_bitmap.bmHeight, m_bitmap.bmWidth, m_bitmap.bmHeight);

    //  显示图标
    m_wndSizeIcon.ShowWindow(m_bShowSizeIcon);

return TRUE;  // return TRUE unless you set the focus to a control
              // EXCEPTION: OCX Property Pages should return FALSE
}

void CResizeDialog::OnSizing(UINT nSide, LPRECT lpRect)
{
    CDialog::OnSizing(nSide, lpRect);

    //  对话框不能小于初始大小

    int iWidth = lpRect->right - lpRect->left;
    int iHeight = lpRect->bottom - lpRect->top;

    if (iWidth <= m_iMinWidth)
        lpRect->right = lpRect->left + m_iMinWidth;
  
    if(iHeight <= m_iMinHeight)
        lpRect->bottom = lpRect->top + m_iMinHeight;
}

BOOL CResizeDialog::SetControlProperty(PDLGCTLINFO lp, int nElements)
{
    //  设置控件数组信息

    if (NULL == lp)
        return FALSE;

    if (nElements <= 0)
        return FALSE;

    m_pControlArray = lp;
    m_iControlNumber = nElements;

    return TRUE;
}

void CResizeDialog::ShowSizeIcon(BOOL bShow /*=TRUE*/)
{
    m_bShowSizeIcon = bShow;
}

#10


对了哈,刚才贴的源文件中有一个#include "ShowMapping.h"这个东东可以去掉的哈,是我自己的一个程序,需要用到CResizeDialog这个类的。
使用这个类时注意的问题:
1.在需要resize的Dialog里#include "ResizeDialog.h"
2.将需要resize的Dialog属性设置为Resizing.
3.将需要resize的Dialog的类里边所有CDialog替换为CResizeDialog;
4.在需要resize的Dialog的OnInitDialog()函数里添加下面类似的代码就OK了:
//  控件信息数组
static DLGCTLINFO  dcMenuGroup[] = 
{
{IDOK, MOVEXY, 50},
{IDCANCEL, MOVEXY, 50},
{IDC_VERSION,MOVEXY,100},
{IDC_MAP,MOVEY,50},
{IDC_SCROLLBAR_ROW,MOVEY,50},
{IDC_SCROLLBAR_COL,MOVEX,50},
{IDC_MAGNIFIER,MOVEXY,50},
{IDC_GROUP1,ELASTICX,50},
{IDC_GROUP2,ELASTICX,50},
{IDC_GROUP2,MOVEY,50},
{IDC_EDIT_DATAPATH,ELASTICX,50},
{IDC_EDIT_LOTID,ELASTICX,50},
{IDC_EDIT_DEVICE,ELASTICX,50},
{IDC_EDIT_TESTERID,ELASTICX,50},
{IDC_EDIT_TESTERID,MOVEY,50},
{IDC_EDIT_PCID,ELASTICX,50},
{IDC_EDIT_PCID,MOVEY,50},
{IDC_EDIT_STARTTIME,ELASTICX,50},
{IDC_EDIT_STARTTIME,MOVEY,50},
{IDC_EDIT_ENDTIME,ELASTICX,50},
{IDC_EDIT_ENDTIME,MOVEY,50},
{IDC_EDIT_PASS,ELASTICX,50},
{IDC_EDIT_PASS,MOVEY,50},
{IDC_EDIT_TOTAL,ELASTICX,50},
{IDC_EDIT_TOTAL,MOVEY,50},
{IDC_EDIT_YIELD,ELASTICX,50},
{IDC_EDIT_YIELD,MOVEY,50},
{IDC_LIST_RAWDATA,ELASTICXY,50},
{IDC_LIST_BINPERCENT,ELASTICXY,50},
{IDC_LIST_BINPERCENT,MOVEY,50},
{IDC_BTN_MAPBINSELECT,MOVEXY,50},
{IDC_BTN_MAPSETTING,MOVEXY,50},
{IDC_BTN_MAPSTYLE,MOVEXY,50},
{IDC_BTN_SAVE,MOVEXY,50},
{IDC_BTN_MAG,MOVEXY,50},
{IDC_BTN_QUERY,MOVEXY,50},
{IDC_STATIC_YIELD,MOVEY,50},
{IDC_STATIC_TOTAL,MOVEY,50},
{IDC_STATIC_PASS,MOVEY,50},
{IDC_STATIC_ENDTIME,MOVEY,50},
{IDC_STATIC_STARTTIME,MOVEY,50},
{IDC_STATIC_PCID,MOVEY,50},
{IDC_STATIC_TESTERID,MOVEY,50},
{IDC_STATIC_X,MOVEY,50},
{IDC_STATIC_Y,MOVEY,50},
{IDC_EDIT_X,ELASTICX,50},
{IDC_EDIT_X,MOVEY,50},
{IDC_EDIT_Y,ELASTICX,50},
{IDC_EDIT_Y,MOVEY,50},
{IDC_STATIC_NOTCH,MOVEY,50},
{IDC_EDIT_NOTCH,ELASTICX,50},
{IDC_EDIT_NOTCH,MOVEY,50},
};
//  设置控件信息
SetControlProperty(dcMenuGroup, sizeof(dcMenuGroup)/sizeof(DLGCTLINFO));