看看我的类: // MyResize.h: interface for the CMyResize class. // //////////////////////////////////////////////////////////////////////#if !defined(AFX_MYRESIZE_H__7D7EE510_B6C1_4267_AD7F_137AA51C4743__INCLUDED_) #define AFX_MYRESIZE_H__7D7EE510_B6C1_4267_AD7F_137AA51C4743__INCLUDED_#if _MSC_VER > 1000 #pragma once #endif // _MSC_VER > 1000const int SXYZ = 2; const int STOBOOT = 4; const int STORIGHT = 8; const int STOLEFT = 16;class CRegObject { public: UINT m_nType; int m_nX; int m_nY; int m_nW; int m_nH; UINT m_nID; CRegObject(); void SetReg(UINT nID, UINT nT, int x, int y, int w, int h); virtual ~CRegObject(); };class CMyResize { public: CMyResize(); CMyResize(CWnd* pParent, int num); virtual ~CMyResize(); public: CWnd* m_pParent; int m_nObjNum; int m_nObj; CRegObject* m_pObj; public: void Register(UINT nID, UINT nType, int x=0, int y=0, int w=0, int h=0); void Register(UINT nID, int x, int y, int w, int h); void Resize(); void SetResize(CRegObject& pObj); };#endif // !defined(AFX_MYRESIZE_H__7D7EE510_B6C1_4267_AD7F_137AA51C4743__INCLUDED_)
// MyResize.cpp: implementation of the CMyResize class. // ////////////////////////////////////////////////////////////////////// #include "MyResize.h"#ifdef _DEBUG #undef THIS_FILE static char THIS_FILE[]=__FILE__; #define new DEBUG_NEW #endif////////////////////////////////////////////////////////////////////// // Construction/Destruction //////////////////////////////////////////////////////////////////////CRegObject::CRegObject() { } void CRegObject::SetReg(UINT nID, UINT nT, int x, int y, int w, int h) { m_nID = nID; m_nType = nT; m_nX = x; m_nY = y; m_nW = w; m_nH = h; } CRegObject::~CRegObject() { }CMyResize::CMyResize() { m_nObjNum = 0; }CMyResize::CMyResize(CWnd* pParent, int num) { ASSERT(num > 0); m_pParent = pParent; m_nObjNum = num; m_nObj = 0; m_pObj = new CRegObject[num](); }void CMyResize::Register(UINT nID, UINT nType, int x, int y, int w, int h) { ASSERT(m_nObj < m_nObjNum); m_pObj[m_nObj].SetReg(nID, nType, x, y, w, h); m_nObj ++; }void CMyResize::Register(UINT nID, int x, int y, int w, int h) { Register(nID, SXYZ, x, y, w, h); }void CMyResize::Resize() { for(int i = 0; i < m_nObj; i++) { SetResize(m_pObj[i]); } }void CMyResize::SetResize(CRegObject& pObj) { CRect reClient, reObj; CWnd* p = m_pParent->GetDlgItem(pObj.m_nID); m_pParent->GetClientRect(&reClient);
MoveWindow or SetWindowPos来设置位置、大小。
//
//////////////////////////////////////////////////////////////////////#if !defined(AFX_MYRESIZE_H__7D7EE510_B6C1_4267_AD7F_137AA51C4743__INCLUDED_)
#define AFX_MYRESIZE_H__7D7EE510_B6C1_4267_AD7F_137AA51C4743__INCLUDED_#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000const int SXYZ = 2;
const int STOBOOT = 4;
const int STORIGHT = 8;
const int STOLEFT = 16;class CRegObject
{
public:
UINT m_nType;
int m_nX;
int m_nY;
int m_nW;
int m_nH;
UINT m_nID;
CRegObject();
void SetReg(UINT nID, UINT nT, int x, int y, int w, int h);
virtual ~CRegObject();
};class CMyResize
{
public:
CMyResize();
CMyResize(CWnd* pParent, int num);
virtual ~CMyResize();
public:
CWnd* m_pParent;
int m_nObjNum;
int m_nObj;
CRegObject* m_pObj;
public:
void Register(UINT nID, UINT nType, int x=0, int y=0, int w=0, int h=0);
void Register(UINT nID, int x, int y, int w, int h);
void Resize();
void SetResize(CRegObject& pObj);
};#endif // !defined(AFX_MYRESIZE_H__7D7EE510_B6C1_4267_AD7F_137AA51C4743__INCLUDED_)
// MyResize.cpp: implementation of the CMyResize class.
//
//////////////////////////////////////////////////////////////////////#include "MyResize.h"#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////CRegObject::CRegObject()
{
}
void CRegObject::SetReg(UINT nID, UINT nT, int x, int y, int w, int h)
{
m_nID = nID;
m_nType = nT;
m_nX = x;
m_nY = y;
m_nW = w;
m_nH = h;
}
CRegObject::~CRegObject()
{
}CMyResize::CMyResize()
{
m_nObjNum = 0;
}CMyResize::CMyResize(CWnd* pParent, int num)
{
ASSERT(num > 0);
m_pParent = pParent;
m_nObjNum = num;
m_nObj = 0;
m_pObj = new CRegObject[num]();
}void CMyResize::Register(UINT nID, UINT nType, int x, int y, int w, int h)
{
ASSERT(m_nObj < m_nObjNum);
m_pObj[m_nObj].SetReg(nID, nType, x, y, w, h);
m_nObj ++;
}void CMyResize::Register(UINT nID, int x, int y, int w, int h)
{
Register(nID, SXYZ, x, y, w, h);
}void CMyResize::Resize()
{
for(int i = 0; i < m_nObj; i++)
{
SetResize(m_pObj[i]);
}
}void CMyResize::SetResize(CRegObject& pObj)
{
CRect reClient, reObj; CWnd* p = m_pParent->GetDlgItem(pObj.m_nID);
m_pParent->GetClientRect(&reClient);
if(pObj.m_nType == SXYZ)
{ }
else
{
if(pObj.m_nType & STOBOOT)
{
p->GetWindowRect(&reObj);
m_pParent->ScreenToClient(&reObj);
p->MoveWindow(reObj.left, reObj.top, reObj.Width(), reClient.Height() - reObj.top);
}
if(pObj.m_nType & STORIGHT)
{
p->GetWindowRect(&reObj);
m_pParent->ScreenToClient(&reObj);
p->MoveWindow(reObj.left, reObj.top, reClient.Width() - reObj.left, reObj.Height());
}
}
}CMyResize::~CMyResize()
{
if(m_nObjNum > 0)
delete []m_pObj;
}
// MyResize.h: interface for the CMyResize class.
//
//////////////////////////////////////////////////////////////////////#if !defined(AFX_MYRESIZE_H__7D7EE510_B6C1_4267_AD7F_137AA51C4743__INCLUDED_)
#define AFX_MYRESIZE_H__7D7EE510_B6C1_4267_AD7F_137AA51C4743__INCLUDED_#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000const int SXYZ = 2;
const int STOBOOT = 4;
const int STORIGHT = 8;
const int STOLEFT = 16;class CRegObject
{
public:
UINT m_nType;
int m_nX;
int m_nY;
int m_nW;
int m_nH;
UINT m_nID;
CRegObject();
void SetReg(UINT nID, UINT nT, int x, int y, int w, int h);
virtual ~CRegObject();
};class CMyResize
{
public:
CMyResize();
CMyResize(CWnd* pParent, int num);
virtual ~CMyResize();
public:
CWnd* m_pParent;
int m_nObjNum;
int m_nObj;
CRegObject* m_pObj;
public:
void Register(UINT nID, UINT nType, int x=0, int y=0, int w=0, int h=0);
void Register(UINT nID, int x, int y, int w, int h);
void Resize();
void SetResize(CRegObject& pObj);
};#endif // !defined(AFX_MYRESIZE_H__7D7EE510_B6C1_4267_AD7F_137AA51C4743__INCLUDED_)
//
//////////////////////////////////////////////////////////////////////
#include "MyResize.h"#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////CRegObject::CRegObject()
{
}
void CRegObject::SetReg(UINT nID, UINT nT, int x, int y, int w, int h)
{
m_nID = nID;
m_nType = nT;
m_nX = x;
m_nY = y;
m_nW = w;
m_nH = h;
}
CRegObject::~CRegObject()
{
}CMyResize::CMyResize()
{
m_nObjNum = 0;
}CMyResize::CMyResize(CWnd* pParent, int num)
{
ASSERT(num > 0);
m_pParent = pParent;
m_nObjNum = num;
m_nObj = 0;
m_pObj = new CRegObject[num]();
}void CMyResize::Register(UINT nID, UINT nType, int x, int y, int w, int h)
{
ASSERT(m_nObj < m_nObjNum);
m_pObj[m_nObj].SetReg(nID, nType, x, y, w, h);
m_nObj ++;
}void CMyResize::Register(UINT nID, int x, int y, int w, int h)
{
Register(nID, SXYZ, x, y, w, h);
}void CMyResize::Resize()
{
for(int i = 0; i < m_nObj; i++)
{
SetResize(m_pObj[i]);
}
}void CMyResize::SetResize(CRegObject& pObj)
{
CRect reClient, reObj; CWnd* p = m_pParent->GetDlgItem(pObj.m_nID);
m_pParent->GetClientRect(&reClient);
if(pObj.m_nType == SXYZ)
{ }
else
{
if(pObj.m_nType & STOBOOT)
{
p->GetWindowRect(&reObj);
m_pParent->ScreenToClient(&reObj);
p->MoveWindow(reObj.left, reObj.top, reObj.Width(), reClient.Height() - reObj.top);
}
if(pObj.m_nType & STORIGHT)
{
p->GetWindowRect(&reObj);
m_pParent->ScreenToClient(&reObj);
p->MoveWindow(reObj.left, reObj.top, reClient.Width() - reObj.left, reObj.Height());
}
}
}CMyResize::~CMyResize()
{
if(m_nObjNum > 0)
delete []m_pObj;
}