使用OnSizing的改進版html
該例程用處爲將窗口限制了大小,而且只容許上下拉伸。須要注意的是WM_GETMINMAXINFO消息在窗口繪製前也會被響應,因此在獲取窗初始大小時要注意判斷。spa
聲明:htm
class CMyDlg : public CDialogEx { // .......... private: CRect miniSize; public: afx_msg void OnGetMinMaxInfo(MINMAXINFO* lpMMI); // .......... };
消息:blog
BEGIN_MESSAGE_MAP(CMyDlg, CDialogEx) ON_WM_GETMINMAXINFO() END_MESSAGE_MAP()
定義:get
void CMyDlg::OnGetMinMaxInfo(MINMAXINFO* lpMMI) { if (miniSize.IsRectNull()) { GetWindowRect(&miniSize); miniSize.bottom -= miniSize.top; miniSize.right -= miniSize.left; miniSize.top = miniSize.left = 0; } if (!miniSize.IsRectNull()) { lpMMI->ptMinTrackSize.x = miniSize.right; lpMMI->ptMinTrackSize.y = miniSize.bottom; lpMMI->ptMaxTrackSize.x = miniSize.right; lpMMI->ptMaxTrackSize.y = GetSystemMetrics(SM_CYSCREEN); } CDialogEx::OnGetMinMaxInfo(lpMMI); }