該例程用處為將窗口限制了大小,並且只允許上下拉伸。需要注意的是WM_GETMINMAXINFO消息在窗口繪制前也會被響應,所以在獲取窗初始大小時要注意判斷。
聲明:
class CMyDlg : public CDialogEx { // .......... public: afx_msg void OnGetMinMaxInfo(MINMAXINFO* lpMMI); // .......... };
消息:
BEGIN_MESSAGE_MAP(CMyDlg, CDialogEx) ON_WM_GETMINMAXINFO() END_MESSAGE_MAP()
定義:
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); }