[VC]禁止窗体右上角的最大化最小化关闭按钮

//使最小化按钮无效
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);
}


如果给你带来帮助,欢迎微信或支付宝扫一扫,赞一下。