禁止对话框窗口的改变和实现窗口的拉伸

1.禁止对话框窗口的改变

(1)响应WM_SYSCOMMAND 消息

void CMfcDemoDlg::OnSysCommand(UINT nID, LPARAM lParam)
{


 if (nID == SC_MOVE || nID==SC_MINIMIZE||nID==SC_MAXIMIZE||SC_CLOSE)
  return;
 else
  CDialog::OnSysCommand(nID, lParam);

}

 

此函数的功能是使对话框禁止改变大小和最大化、最小化、关闭按钮失效。

(2)

LRESULT CMfcDemoDlg::OnNcHitTest(CPoint point)
{
 // TODO: 在此添加消息处理程序代码和/或调用默认值

 UINT ret =(UINT)CDialog::OnNcHitTest(point);

 if(HTCAPTION == ret)
  return HTCLIENT;

 return ret;

 


}

(3)LRESULT CMfcDemoDlg::OnNcHitTest(CPoint point)
{
 // TODO: 在此添加消息处理程序代码和/或调用默认值

 UINT ret =(UINT)CDialog::OnNcHitTest(point);

 //if语句的前两行是用来禁止改变大小的,最后一行是用来禁止移动的

 if(HTTOP ==ret || HTBOTTOM == ret || HTLEFT == ret || HTRIGHT == ret
  || HTBOTTOMLEFT == ret ||HTBOTTOMRIGHT == ret || HTTOPLEFT == ret || HTTOPRIGHT == ret       || HTCAPTION== ret)
  return HTCLIENT;

 return ret;

 

 

}

2.

随意拉伸无标题对话框的大小

首先把对话框的Border的属性设为None
然后将System Menu属性设为False

响应这个函数
复制代码
  1. LRESULT CtestDlg::OnNcHitTest(CPoint point)
  2. {
  3.  // TODO: 在此添加消息处理程序代码和/或调用默认值
  4.  CRect rect;
  5.  GetWindowRect(&rect);
  6.  if(point.x <= rect.left + 5 && point.y <= rect.top + 5)
  7.  {
  8.   return HTTOPLEFT;
  9.  }
  10.  else if(point.x >= rect.right - 5 && point.y <= rect.top + 5)
  11.  {
  12.   return HTTOPRIGHT;
  13.  }
  14.  else if(point.x <= rect.left + 5 && point.y >= rect.bottom - 5)
  15.  {
  16.   return HTBOTTOMLEFT;
  17.  }
  18.  else if(point.x >= rect.right - 5 && point.y >= rect.bottom - 5)
  19.  {
  20.   return HTBOTTOMRIGHT;
  21.  }
  22.  else if(point.x <= rect.left + 5)
  23.  {
  24.   return HTLEFT;
  25.  }
  26.  else if(point.x >= rect.right - 5)
  27.  {
  28.   return HTRIGHT;
  29.  }
  30.  else if(point.y <= rect.top + 5)
  31.  {
  32.   return HTTOP;
  33.  }
  34.  else if(point.y >= rect.bottom - 5)
  35.  {
  36.   return HTBOTTOM;
  37.  }
  38.  return CDialog::OnNcHitTest(point);
  39. }

 

 

你可能感兴趣的:(System,border,menu)