Created
July 8, 2011 05:23
-
-
Save xkyii/1071198 to your computer and use it in GitHub Desktop.
控制窗口按钮
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//使最小化按钮无效 | |
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); | |
// mnu->EnableMenuItem(SC_CLOSE,MF_BYCOMMAND|MF_GRAYED); 也可 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment