清泛IT社区

标题: c++关闭按钮灰掉 [打印本页]

作者: 清泛网    时间: 2016-04-07 10:48
标题: c++关闭按钮灰掉
(, 下载次数: 118)
通过系统菜单灰掉:
  1. //获得系统菜单
  2. CMenu *pMenu = GetSystemMenu(false);
  3. //获得关闭按钮ID
  4. UINT ID = pMenu->GetMenuItemID(pMenu->GetMenuItemCount()-1);
  5. //使关闭按钮无效
  6. pMenu->EnableMenuItem(ID,MF_GRAYED);
复制代码
启用:
  1. //获得系统菜单
  2. CMenu *pMenu = GetSystemMenu(false);
  3. //获得关闭按钮ID
  4. UINT ID = pMenu->GetMenuItemID(pMenu->GetMenuItemCount()-1);
  5. //使关闭按钮可用
  6. pMenu->EnableMenuItem(ID,MF_ENABLED);
复制代码

同理,最大化、最小化按钮灰掉&启用代码如下:
  1. //禁用最小化按钮
  2. void CMainFrame::OnMenudismin()
  3. {
  4.         //获得窗口风格
  5.         Style = ::GetWindowLong(m_hWnd,GWL_STYLE);
  6.         //设置新的风格
  7.         Style &= ~(WS_MINIMIZEBOX);
  8.         ::SetWindowLong(m_hWnd,GWL_STYLE,Style);
  9.         GetWindowRect(&Rect);
  10.         //重画窗口边框
  11.         ::SetWindowPos(m_hWnd,HWND_TOP,Rect.left,Rect.top,Rect.Width(),Rect.Height(),SWP_DRAWFRAME);
  12. }
  13. //使最小化按钮有效
  14. void CMainFrame::OnMenuablemin()
  15. {
  16.         //获得窗口风格
  17.         Style = ::GetWindowLong(m_hWnd,GWL_STYLE);
  18.         //设置新的风格
  19.         Style |= WS_MINIMIZEBOX;
  20.         ::SetWindowLong(m_hWnd,GWL_STYLE,Style);
  21.         GetWindowRect(&Rect);
  22.         //重画窗口边框
  23.         ::SetWindowPos(m_hWnd,HWND_TOP,Rect.left,Rect.top,Rect.Width(),Rect.Height(),SWP_DRAWFRAME);
  24. }


  25. //禁用最大化按钮
  26. void CMainFrame::OnMenudismax()
  27. {
  28.         //获得窗口风格
  29.         Style = ::GetWindowLong(m_hWnd,GWL_STYLE);
  30.         //设置新的风格
  31.         Style &= ~(WS_MAXIMIZEBOX);
  32.         ::SetWindowLong(m_hWnd,GWL_STYLE,Style);
  33.         GetWindowRect(&Rect);
  34.         //重画窗口边框
  35.         ::SetWindowPos(m_hWnd,HWND_TOP,Rect.left,Rect.top,Rect.Width(),Rect.Height(),SWP_DRAWFRAME);
  36. }
  37. //使最大化按钮有效
  38. void CMainFrame::OnMenuablemax()
  39. {
  40.         //获得窗口风格
  41.         Style = ::GetWindowLong(m_hWnd,GWL_STYLE);
  42.         //设置新的风格
  43.         Style |= WS_MAXIMIZEBOX;
  44.         ::SetWindowLong(m_hWnd,GWL_STYLE,Style);
  45.         GetWindowRect(&Rect);
  46.         //重画窗口边框
  47.         ::SetWindowPos(m_hWnd,HWND_TOP,Rect.left,Rect.top,Rect.Width(),Rect.Height(),SWP_DRAWFRAME);
  48. }
复制代码







欢迎光临 清泛IT社区 (https://bbs.tsingfun.com/) Powered by Discuz! X3.3