资源简介

自定义类CSelfResizeWindow实现窗口和控件的自适应调整,根据屏幕尺寸调整大小。实现的非常简单,而且通用性很好,对于控件和窗体都有好用,只要继承这个自定义类,并在你的对话框类的OnInitDialog()函数和OnSize()函数中各加入一行代码就全部OK啦!

资源截图

代码片段和文件信息

#include “stdafx.h“
#include “SelfResizeWindow.h“

CSelfResizeWindow::CSelfResizeWindow(int wOff int hOff)
{
m_Dlg = NULL;
m_WidthOff = wOff; // 10
m_HeightOff = hOff;// 10
m_W = GetSystemMetrics(SM_CXSCREEN);
m_H = GetSystemMetrics(SM_CYSCREEN);
m_ChildWndList.clear();
}

CSelfResizeWindow::~CSelfResizeWindow()
{
m_Dlg = NULL;
m_ChildWndList.clear();
}

bool CSelfResizeWindow::Rectify()
{
if (m_Dlg == NULL){
return false;
}
RECT rct;
m_Dlg->GetClientRect(&rct);
int w = rct.right - rct.left;
int h = rct.bottom - rct.top;

double wTimes = w * 1.0 / m_W;
double hTimes = h * 1.0 / m_H;

map::iterator it = m_ChildWndList.begin();
while (it != m_ChildWndList.end())
{
CWnd* w = m_Dlg->GetDlgItem(it->first);
RECT rct = it->second;
rct.left *= wTimes;
rct.right *= wTimes;
rct.top *= hTimes;
rct.bottom *= hTimes;
if (w){
w->MoveWindow(&rct FALSE);
}
it++;
}
m_Dlg->Invalidate(TRUE);
return true;
}

bool CSelfResizeWindow::Init(CDialog*dlg int beginId int endId)
{
if (dlg == NULL){
return false;
}

m_Dlg = dlg;
m_ChildWndList.clear();
RECT parentRct;
m_Dlg->GetClientRect(&parentRct);
m_W = parentRct.right - parentRct.left;
m_H = parentRct.bottom - parentRct.top;

for (int i=beginId; i<=endId; i++){
CWnd* w = m_Dlg->GetDlgItem(i);
if (w){
RECT rct;
w->GetWindowRect(&rct);
m_Dlg->ScreenToClient(&rct);
m_ChildWndList.insert(make_pair(i rct));
}
}
return true;
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件      93184  2015-08-31 14:33  VC++窗口和控件自适应屏幕尺寸\SelfResizing\Release\SelfResizing.exe

     文件    4942848  2015-08-31 14:33  VC++窗口和控件自适应屏幕尺寸\SelfResizing\Release\SelfResizing.pdb

     文件       2827  2015-08-31 14:05  VC++窗口和控件自适应屏幕尺寸\SelfResizing\SelfResizing\ReadMe.txt

     文件       8480  2015-08-31 14:33  VC++窗口和控件自适应屏幕尺寸\SelfResizing\SelfResizing\Release\BuildLog.htm

     文件         67  2015-08-31 14:33  VC++窗口和控件自适应屏幕尺寸\SelfResizing\SelfResizing\Release\mt.dep

     文件     223005  2015-08-31 14:09  VC++窗口和控件自适应屏幕尺寸\SelfResizing\SelfResizing\Release\SelfResizeWindow.obj

     文件        851  2015-08-31 14:33  VC++窗口和控件自适应屏幕尺寸\SelfResizing\SelfResizing\Release\SelfResizing.exe.intermediate.manifest

     文件     150877  2015-08-31 14:15  VC++窗口和控件自适应屏幕尺寸\SelfResizing\SelfResizing\Release\SelfResizing.obj

     文件   38993920  2015-08-31 14:09  VC++窗口和控件自适应屏幕尺寸\SelfResizing\SelfResizing\Release\SelfResizing.pch

     文件      69684  2015-08-31 14:33  VC++窗口和控件自适应屏幕尺寸\SelfResizing\SelfResizing\Release\SelfResizing.res

     文件     168511  2015-08-31 14:33  VC++窗口和控件自适应屏幕尺寸\SelfResizing\SelfResizing\Release\SelfResizingDlg.obj

     文件    4550068  2015-08-31 14:09  VC++窗口和控件自适应屏幕尺寸\SelfResizing\SelfResizing\Release\stdafx.obj

     文件    1108992  2015-08-31 14:33  VC++窗口和控件自适应屏幕尺寸\SelfResizing\SelfResizing\Release\vc90.idb

     文件    3788800  2015-08-31 14:33  VC++窗口和控件自适应屏幕尺寸\SelfResizing\SelfResizing\Release\vc90.pdb

     文件      67777  2007-11-28 16:21  VC++窗口和控件自适应屏幕尺寸\SelfResizing\SelfResizing\res\SelfResizing.ico

     文件        368  2015-08-31 14:05  VC++窗口和控件自适应屏幕尺寸\SelfResizing\SelfResizing\res\SelfResizing.rc2

     文件        776  2015-08-31 14:10  VC++窗口和控件自适应屏幕尺寸\SelfResizing\SelfResizing\resource.h

     文件       1534  2015-08-31 14:09  VC++窗口和控件自适应屏幕尺寸\SelfResizing\SelfResizing\SelfResizeWindow.cpp

     文件        593  2015-08-31 14:07  VC++窗口和控件自适应屏幕尺寸\SelfResizing\SelfResizing\SelfResizeWindow.h

     文件     105668  2015-08-31 14:33  VC++窗口和控件自适应屏幕尺寸\SelfResizing\SelfResizing\SelfResizing.aps

     文件       1731  2015-08-31 14:05  VC++窗口和控件自适应屏幕尺寸\SelfResizing\SelfResizing\SelfResizing.cpp

     文件        481  2015-08-31 14:05  VC++窗口和控件自适应屏幕尺寸\SelfResizing\SelfResizing\SelfResizing.h

     文件       5349  2015-08-31 14:33  VC++窗口和控件自适应屏幕尺寸\SelfResizing\SelfResizing\SelfResizing.rc

     文件       5604  2015-08-31 14:09  VC++窗口和控件自适应屏幕尺寸\SelfResizing\SelfResizing\SelfResizing.vcproj

     文件       1427  2015-08-31 14:33  VC++窗口和控件自适应屏幕尺寸\SelfResizing\SelfResizing\SelfResizing.vcproj.EFDD10259FB44A0.Administrator.user

     文件       2567  2015-08-31 14:33  VC++窗口和控件自适应屏幕尺寸\SelfResizing\SelfResizing\SelfResizingDlg.cpp

     文件        538  2015-08-31 14:15  VC++窗口和控件自适应屏幕尺寸\SelfResizing\SelfResizing\SelfResizingDlg.h

     文件        145  2015-08-31 14:05  VC++窗口和控件自适应屏幕尺寸\SelfResizing\SelfResizing\stdafx.cpp

     文件       1854  2015-08-31 14:05  VC++窗口和控件自适应屏幕尺寸\SelfResizing\SelfResizing\stdafx.h

     文件       1030  2015-08-31 14:05  VC++窗口和控件自适应屏幕尺寸\SelfResizing\SelfResizing\targetver.h

............此处省略13个文件信息

评论

共有 条评论