图一 |
图二 |
图三 |
void CMainFrame::ViewMode(int nViewType) { CRect ClientRect; CRect WindowRect; CRect ToolbarRect; CRect StatusbarRect; //获取窗体、客户区及工具条大小 WindowRect = m_WindowRect; ClientRect = m_ClientRect; m_wndToolBar.GetWindowRect(&ToolbarRect); //获取边框及标题栏大小 int borderHeight = GetSystemMetrics(SM_CYBORDER); int captionHeight = GetSystemMetrics(SM_CYCAPTION); //获取状态条大小 CStatusBar* pStatus = (CStatusBar*) AfxGetApp()->m_pMainWnd->GetDescendantWindow(AFX_IDW_STATUS_BAR); pStatus->GetWindowRect(&StatusbarRect); //停靠工具条 DockControlBar(&m_wndToolBar); int CompactCx; //新窗体宽 int CompactCy; //新窗体高 //以多种模式显示 switch(nViewType) { case 0: //正常显示模式 { //显示菜单 if ( hMenu != NULL ) ::SetMenu( m_hWnd, hMenu ); //显示状态条 pStatus->ShowWindow(SW_SHOW); //新窗体宽、高 CompactCx=WindowRect.Width(); CompactCy=WindowRect.Height(); } break; case 1: //简洁显示模式 { //显示菜单 if ( hMenu != NULL ) ::SetMenu( m_hWnd, hMenu ); //隐藏状态条 pStatus->ShowWindow(SW_HIDE); //新窗体宽、高 CompactCx=WindowRect.Width(); CompactCy=WindowRect.Height() - ClientRect.Height() + ToolbarRect.Height() - borderHeight; } break; case 2: //精简显示模式 { //隐藏菜单 hMenu = ::GetMenu(m_hWnd); ::SetMenu( m_hWnd, NULL ); //隐藏状态条 pStatus->ShowWindow(SW_HIDE); //新窗体宽、高 CompactCx=WindowRect.Width(); CompactCy=captionHeight + ToolbarRect.Height() + borderHeight*2; } break; } //设置新窗体显示 SetWindowPos( &wndTop, WindowRect.left, WindowRect.top, CompactCx, CompactCy, SWP_SHOWWINDOW); } |