关于MFC窗口最大化是控件位置自动调整

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

1.将窗口属相更改为DialogFrame2.在对应窗口的Dlg.cpp文件如下位置添加ON_WM_SIZE()3.在对应头文件中添加4.添加OnSize()函数代码如下:voidCMy3Dlg::OnSize(UINTnType,intcx,intcy){CDialog::OnSize(nType,cx,cy);//TODO:Addyourmessagehandlercodehereif(nType==SIZE_RESTORED||nType==SIZE_MAXIMIZED){resize();}}5.添加resize()函数代码如下:voidCMy3Dlg::resize(){floatfsp[2];POINTNewp;//获取现在对话框的大小CRectrecta;GetClientRect(&recta);//取客户区大小Newp.x=recta.right-recta.left;Newp.y=recta.bottom-recta.top;fsp[0]=(float)Newp.x/Old.x;fsp[1]=(float)Newp.y/Old.y;CRectRect;intwoc;CPointOldTLPoint,TLPoint;//左上角CPointOldBRPoint,BRPoint;//右下角HWNDhwndChild=::GetWindow(m_hWnd,GW_CHILD);//列出所有控件while(hwndChild){woc=::GetDlgCtrlID(hwndChild);//取得IDGetDlgItem(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=Newp;}

1 / 3
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功