// lxDialog.cpp: implementation of the ClxDialog class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "decode.h"
#include "lxDialog.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
// 表示可改变大小的图标ID
#ifndef OBM_SIZE
#define OBM_SIZE 32766
#endif
//设置对话框能调整的最小长宽
#define MINDLG_HEIGHT
#define MINDLG_WIDTH
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
ClxDialog::~ClxDialog()
{
}
ClxDialog::ClxDialog(UINT nID, CWnd* pParent ): CDialog(nID, pParent), m_iClientWidth(0),
m_iClientHeight(0), m_iMinWidth(0), m_iMinHeight(0), m_pControlArray(NULL),
m_iControlNumber(0), m_bShowSizeIcon(TRUE)
{}
BEGIN_MESSAGE_MAP(ClxDialog, CDialog)
ON_WM_SIZE()
ON_WM_SIZING()
END_MESSAGE_MAP()
BOOL ClxDialog::OnInitDialog()
{CDialog::OnInitDialog();
// 设置对话框为可变大小的
ModifyStyle(0, WS_SIZEBOX);
//设置对话框属性,使它能支持鼠标拖动改变大小
ModifyStyle( NULL, WS_THICKFRAME);
// 以对话框的初始大小作为对话框的宽度和高度的最小值
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;
}
void ClxDialog::OnSize(UINT nType, int cx, int cy)
{
CDialog::OnSize(nType, cx, cy);
// 对话框宽度和高度的增量
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);
// 记录对话框client区域的大小
if (nType != SIZE_MINIMIZED)
{
m_iClientWidth = cx;
m_iClientHeight = cy;
}
}
void ClxDialog::OnSizing(UINT nSide, LPRECT lpRect)
{
CDialog::OnSizing(nSide, lpRect);
//设置对话框能调整的最小长和宽
CRect rect(pRect);
int width = rect.Width();
int height = rect.Height();
switch(fwSide)
{
case WMSZ_BOTTOM:
{
if(height < MINDLG_HEIGHT)
pRect->bottom = pRect->top + MINDLG_HEIGHT;
break;
}
case WMSZ_LEFT:
{
if(width < MINDLG_WIDTH)
pRect->left = pRect->right - MINDLG_WIDTH;
break;
}
case WMSZ_RIGHT:
{
if (width < MINDLG_WIDTH)
pRect->right = pRect->left + MINDLG_WIDTH;
break;
}
case WMSZ_TOP:
{
if (height < MINDLG_HEIGHT)
pRect->top = pRect->bottom - MINDLG_HEIGHT;
break;
}
case WMSZ_TOPLEFT:
{
if (width < MINDLG_WIDTH)
pRect->left = pRect->right - MINDLG_WIDTH;
if (height < MINDLG_HEIGHT)
pRect->top = pRect->bottom - MINDLG_HEIGHT;
break;
}
case WMSZ_TOPRIGHT:
{
if (width < MINDLG_WIDTH)
pRect->right = pRect->left + MINDLG_WIDTH;
if (height < MINDLG_HEIGHT)
pRect->top = pRect->bottom - MINDLG_HEIGHT;
break;
}
case WMSZ_BOTTOMLEFT:
{
if (width < MINDLG_WIDTH)
pRect->left = pRect->right - MINDLG_WIDTH;
if (height < MINDLG_HEIGHT)
pRect->bottom = pRect->top + MINDLG_HEIGHT;
break;
}
case WMSZ_BOTTOMRIGHT:
{
if (width < MINDLG_WIDTH)
pRect->right = pRect->left + MINDLG_WIDTH;
if (height < MINDLG_HEIGHT)
pRect->bottom = pRect->top + MINDLG_HEIGHT;
break;
}
}
}
BOOL ClxDialog::SetControlProperty(PDLGCTLINFO lp, int nElements)
{
// 设置控件数组信息
if (NULL == lp)
return FALSE;
if (nElements <= 0)
return FALSE;
m_pControlArray = lp;
m_iControlNumber = nElements;
return TRUE;
}
void ClxDialog::ShowSizeIcon(BOOL bShow )
{
m_bShowSizeIcon = bShow;
}
VC 对话框控件自动调整位置
5星 · 超过95%的资源 需积分: 11 115 浏览量
2008-12-24
13:44:16
上传
评论
收藏 55KB RAR 举报
wudizuijimo
- 粉丝: 11
- 资源: 25
最新资源
- libjpeg 编译所需的 Win32.mak vs编译libjpeg
- 自动驾驶-状态估计和定位-粒子滤波实现和源码.pdf
- 数据可视化-智慧物流服务中心大屏页面.zip
- yolov5,SSD 可能使用到的一些代码
- bbbbbbbbbbbbbbbbbb
- 安卓逆向学习笔记之Frida Stalker 还原OLLVM AES.docx
- 安卓逆向学习笔记之unicorn来trace还原OLLVM Base64.docx
- 基于jquery的自定义表格组件实现
- Nessus最新20240426离线安装插件all-2.0.tar.gz
- 最新版本私钥助记词碰撞器大富豪使用python进行制作通过接口的方式进行验证支持多币种多链多网络一分钟万次验证高出货率
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
- 1
- 2
前往页