BOOL Csunboxtest11Dlg::OnInitDialog()
{
CDialogEx::OnInitDialog();
CRect rect;
POINT old;
GetClientRect(&rect); //取得放大前客户区大小
old.x=rect.right-rect.left;
old.y=rect.bottom-rect.top;
SetWindowPos(NULL,0,0,GetSystemMetrics(SM_CXSCREEN),GetSystemMetrics(SM_CYSCREEN),0); //全屏1
//ShowWindow(SW_SHOWMAXIMIZED); //全屏2
CRect recttemp;
CRect recta;
POINT bili;
float fsp[2];
GetClientRect(&recta); //获得全屏后的client大小
bili.x=recta.right-recta.left; // 获得全屏后的xy轴距离
bili.y=recta.bottom-recta.top;
fsp[0]=(float)bili.x/old.x; //计算出全屏前后的比例关系
fsp[1]=(float)bili.y/old.y;
CRect Rect;
int woc;
CPoint OldTLPoint,TLPoint; //左上角
CPoint OldBRPoint,BRPoint; //右下角
HWND hwndChild=::GetWindow(m_hWnd,GW_CHILD); //列出所有控件
while(hwndChild) // 将其中每一个空间都进行比例缩放
{
woc=::GetDlgCtrlID(hwndChild);//取得ID
GetDlgItem(woc)->GetWindowRect(Rect);
ScreenToClient(Rect);
OldTLPoint = Rect.TopLeft();
TLPoint.x = long(OldTLPoint.x*fsp[0]);
TLPoint.y = long(OldTLPoint.y*fsp[1]);
OldBRPoint = Rect.BottomRight();
BRPoint.x = long(OldBRPoint.x *fsp[0]);
BRPoint.y = long(OldBRPoint.y *fsp[1]);
Rect.SetRect(TLPoint,BRPoint);
GetDlgItem(woc)->MoveWindow(Rect,TRUE);
hwndChild=::GetWindow(hwndChild, GW_HWNDNEXT);
}
old=bili;
return TRUE; // 除非将焦点设置到控件,否则返回 TRUE
}
本文介绍了一种在Windows应用程序中实现全屏显示并按比例调整控件位置的方法。通过获取窗口原始尺寸与全屏尺寸的比例,计算出各控件的新坐标,确保全屏时控件布局的准确性。
1279

被折叠的 条评论
为什么被折叠?



