(VC/MFC)禁止对话框(窗口)的大小改变和移动

一、禁止对话框的移动
(1)、第一种方法
为这个对话框添加系统消息过虑处理:
.h中:
...
afx_msg void On SysCommand(UINT nID, LPARAM lParam);
...

.cpp中
BEGIN_MESSAGE_MAP(CXXXDlg, CDialog)
...
ON_WM_SYSCOMMAND()
...
END_MESSAGE_MAP()


void CXXXDlg::On SysCommand(UINT nID, LPARAM lParam)
{
if (nID == SC_MOVE || nID==0xF012)
return;
else
CDialog::On SysCommand(nID, lParam);
}

SC_MOVE就是0xF010。
参考帖子:http://topic.csdn.net/t/20020821/12/957952.html
(2)、第二种方法
.h中:
...
afx_msg UINT On NcHitTest(CPoint point); 
...

.cpp中
BEGIN_MESSAGE_MAP(CXXXDlg, CDialog)
...
ON_WM_NCHITTEST() 
...
END_MESSAGE_MAP()


UINT CXXXDlg::On NcHitTest(CPoint point)
{
    int ret =CDialog::On NcHitTest(point);

    if(HTCAPTION == ret)
       returnHTCLIENT;

    returnret;
}

二、禁止对话框改变大小
.h中:
...
afx_msg UINT On NcHitTest(CPoint point); 
...

.cpp中
BEGIN_MESSAGE_MAP(CXXXDlg, CDialog)
...
ON_WM_NCHITTEST() 
...
END_MESSAGE_MAP()


UINT CXXXDlg::On NcHitTest(CPoint point)
{
    int ret =CDialog::On NcHitTest(point);

   //if语句的前两行是用来禁止改变大小的,最后一行是用来禁止移动的
    if(HTTOP ==ret || HTBOTTOM == ret || HTLEFT == ret || HTRIGHT == ret
      || HTBOTTOMLEFT == ret ||HTBOTTOMRIGHT == ret || HTTOPLEFT == ret || HTTOPRIGHT == ret       || HTCAPTION== ret)
       returnHTCLIENT;

    returnret;
}
参考帖子:http://web.newsfan.net/showpost.php?p=594616

你可能感兴趣的:((VC/MFC)禁止对话框(窗口)的大小改变和移动)