限制窗口拉伸范围——WM_GETMINMAXINFO

使用OnSizing的改进版

该例程用处为将窗口限制了大小,并且只允许上下拉伸。需要注意的是WM_GETMINMAXINFO消息在窗口绘制前也会被响应,所以在获取窗初始大小时要注意判断。

声明:

class CMyDlg : public CDialogEx
{
    // ..........
private:
    CRect miniSize;
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);
}

 

posted @ 2016-03-24 21:55  流忧  阅读(1289)  评论(0编辑  收藏  举报