我们知道窗口大小发生变化时,会触发消息WM_SIZE我们就可以在此消息处理函数中改变控件的大小。
例如我们对话框上有一个列表控件IDC_LIST
初始化时我们可以设置一下它的窗口大小
- //获得客户区坐标
- CRect rect;
- GetClientRect(&rect);
- //移动窗口
- CWnd* pWnd = GetDlgItem(IDC_LIST);
- if (pWnd != NULL)
- {
- pWnd->MoveWindow(10, 10, rect.Width() - 20,rect.Height() - 20);
- }
复制代码 当主窗口大小发生变化时,我们可以基其WM_SIZE消息处理函数内对应更改控件大小。
- void CDemoDlg::OnSize(UINT nType, int cx, int cy)
- {
- CDialog::OnSize(nType, cx, cy);
- //根据父窗口的大小移动窗口
- CWnd* pWnd = GetDlgItem(IDC_LIST);
- if (pWnd != NULL)
- {
- pWnd->MoveWindow(10, 10, cx - 20, cy - 20);
- }
- }
复制代码 nType表示窗口尺寸变化的类型,有最大化SIZE_MAXIMIZED 。最小化等等。
另外两个参数表示窗口新的客户区大小。
这个函数可以查阅MSDN
afx_msg void OnSize( UINT nType, int cx, int cy );
Parameters
nType
Specifies the type of resizing requested. This parameter can be one of the following values:
SIZE_MAXIMIZED Window has been maximized.
SIZE_MINIMIZED Window has been minimized.
SIZE_RESTORED Window has been resized, but neither SIZE_MINIMIZED nor SIZE_MAXIMIZED applies.
SIZE_MAXHIDE Message is sent to all pop-up windows when some other window is maximized.
SIZE_MAXSHOW Message is sent to all pop-up windows when some other window has been restored to its former size.
cx
Specifies the new width of the client area.
cy
Specifies the new height of the client area.
上位机VC MFC程序开发精典实例大全源码与视频讲解配套下载408例 经历1年的编程与录制点击进入查看
如果您认可,可联系功能定制! 如果您着急,充值会员可直接联系发您资料!
|