问个文档/视图结构框架的问题
随便点击一个按钮,让关闭按钮失效
点击另外一个按钮,让关闭按钮可用
怎么实现?
我获得了主窗口框架的指针
CWnd* pWnd = AfxGetApp()-> GetMainWnd();
谢谢了
[解决办法]
//使最小化按钮无效
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);
}