WinBox_Ctrl

//使最小化按无效
void CMainFrame::OnDisableMinbox()
{
  //获得窗口风格
  LONG style = ::GetWindowLong(m_hWnd,GWL_STYLE);

  //设置新的风格
  style &= ~(WS_MINIMIZEBOX);
  ::SetWindowLong(m_hWnd,GWL_STYLE,style);

  //重化窗口边框
  CRect rc;
  GetWindowRect(&rc);
  ::SetWindowPos(m_hWnd,HWND_NOTOPMOST,rc.left,rc.top,rc.Width(),rc.Height(),SWP_DRAWFRAME);
}

//使最大化按钮无效
void CMainFrame::OnDisableMaxbox()
{
  //获得窗口风格
  LONG style = ::GetWindowLong(m_hWnd,GWL_STYLE);

  //设置新的风格
  style &= ~(WS_MAXIMIZEBOX);
  ::SetWindowLong(m_hWnd,GWL_STYLE,style);

  //重化窗口边框
  CRect rc;
  GetWindowRect(&rc);
  ::SetWindowPos(m_hWnd,HWND_NOTOPMOST,rc.left,rc.top,rc.Width(),rc.Height(),SWP_DRAWFRAME);
}

//使关闭按钮无效
void CMainFrame::OnDisableClose()
{
  //获得系统菜单
  CMenu *pMenu = GetSystemMenu(FALSE);

  //获得关闭按钮的ID
  int x = pMenu->GetMenuItemCount();
  UINT pID=pMenu->GetMenuItemID(x-1);

  //使关闭按钮无效
  pMenu->EnableMenuItem(pID, MF_DISABLED);
}


//使最小化按钮有效
void CMainFrame::OnAbleMinbox()
{
  //获得窗口风格
  LONG style = ::GetWindowLong(m_hWnd,GWL_STYLE);

  //设置新的风格
  style |= WS_MINIMIZEBOX;
  ::SetWindowLong(m_hWnd,GWL_STYLE,style);
  //重化窗口边框
  CRect rc;
  GetWindowRect(&rc);
  ::SetWindowPos(m_hWnd,HWND_NOTOPMOST,rc.left,rc.top,rc.Width(),rc.Height(),SWP_DRAWFRAME);  
}

//使最大化按钮有效
void CMainFrame::OnAbleMaxbox()
{
  //获得窗口风格
  LONG style = ::GetWindowLong(m_hWnd,GWL_STYLE);

  //设置新的风格
  style |= WS_MAXIMIZEBOX;
  ::SetWindowLong(m_hWnd,GWL_STYLE,style);

  //重化窗口边框
  CRect rc;
  GetWindowRect(&rc);
  ::SetWindowPos(m_hWnd,HWND_NOTOPMOST,rc.left,rc.top,rc.Width(),rc.Height(),SWP_DRAWFRAME);
}

//使关闭按钮有效
void CMainFrame::OnAbleClose()
{
  //获得系统菜单
  CMenu *pMenu=GetSystemMenu(FALSE);

  //获得关闭按钮的ID
  int x=pMenu->GetMenuItemCount();
  UINT pID=pMenu->GetMenuItemID(x-1);

  //使关闭按钮有效
  pMenu->EnableMenuItem(pID, MF_ENABLED);
}

//使对话框的关闭按钮无效:
  在对话框的OnInitDialog中调用如下代码
  CMenu *mnu=this->GetSystemMenu(FALSE);
  mnu->ModifyMenu(SC_CLOSE,MF_BYCOMMAND|MF_GRAYED);
  // OR
  mnu->EnableMenuItem(SC_CLOSE,MF_BYCOMMAND|MF_GRAYED);

0 コメント: