MFC,在CDialog应用程序中调整控件大小
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了MFC,在CDialog应用程序中调整控件大小相关的知识,希望对你有一定的参考价值。
This OnSize function resizes one large control in a dialog.The one control grows horizontally and vertically to fill the dialog. It's position remains unchanged.
Other controls (buttons etc) would typically be above the one resizable control.
// This OnSize function resizes one large control in a dialog. // The one control grows horizontally and vertically to fill the dialog. It's position remains unchanged. // Other controls (buttons etc) would typically be above the one resizable control. // How to add OnSize: // [1] add to .h: afx_msg void OnSize(UINT nType, int cx, int cy); // [2] add to message map in .cpp: ON_WM_SIZE() // [3] add this OnSize function. void CMyDlg::OnSize(UINT nType, int formWidthArg, int formHeightArg) { CDialog::OnSize(nType, formWidthArg, formHeightArg); // Let dialog resize itself. // http://www.codersource.net/mfc_resize_controls.html // http://wwwusers.brookes.ac.uk/p0071643/resize.htm // get pointer to the control to be resized dynamically CWnd* pCtl = GetDlgItem(IDC_MSFLEXGRID1); if (!pCtl) { return; } // control may not exist yet. CRect rectCtl; // Allocate CRect for control's position. pCtl->GetWindowRect(&rectCtl); // Get control's position. ScreenToClient(&rectCtl); // Convert from absolute screen coordinates to dialog-relative coordinates. // Now resize the control dynamically by calling MoveWindow // rectCtl.left is assumed to be the left, bottom and right margin for the control. pCtl->MoveWindow( rectCtl.left, // x. remains unchanged rectCtl.top, // y. remains unchanged formWidthArg - 2 * rectCtl.left, // w. Grow to fill horizontally formHeightArg - rectCtl.top - rectCtl.left, // h. Grow to fill vertically TRUE) ; return; } // OnSize()
以上是关于MFC,在CDialog应用程序中调整控件大小的主要内容,如果未能解决你的问题,请参考以下文章
C++ MFC - 在 CDialog::OnSize 事件 (GetWindowRect) 上没有引发运行时错误的代码执行失败