vc實現窗口全屏的一些方法


1.

void CXXXDlg::SetFullScreen()
{
	int frameWidth =  GetSystemMetrics(SM_CXFRAME);
	int frameHeight = GetSystemMetrics(SM_CYFRAME);
	int captionHeight = GetSystemMetrics(SM_CYCAPTION);
	int screenWidth = GetSystemMetrics(SM_CXSCREEN);
	int screenHeight = GetSystemMetrics(SM_CYSCREEN);
	CRect rect;
	GetClientRect(&rect);
	rect.left = rect.left - frameWidth;
	rect.top = rect.top - frameHeight - captionHeight ;
	rect.bottom = rect.top + screenHeight + 2 * frameHeight + captionHeight;
	rect.right = rect.left + screenWidth + 2 * frameWidth;
	ShowWindow(SW_HIDE);
	SetWindowPos(&wndTopMost, rect.left, rect.top, rect.Width(), rect.Height(), SWP_SHOWWINDOW);
}
2.

實現全屏顯示:

在CMainFrame類中實現

private:

       BOOL                   m_bFullScreen;        // 全屏顯示標志

       WINDOWPLACEMENT m_OldWndPlacement; // 用來保存原窗口的位置

       CRect                   m_FullScreenRect;      // 表示全屏顯示時的窗口位置

初始化

CMainFrame::CMainFrame()

{

       // TODO: add member initialization code here

       m_bFullScreen = FALSE;

}

添加菜單項以及菜單效應函數

void CMainFrame::OnFullScreen()

{

       // TODO: Add your command handler code here

       GetWindowPlacement(&m_OldWndPlacement);

       CRect WindowRect;

       GetWindowRect(&WindowRect);

       CRect ClientRect;

       RepositionBars(0, 0xffff, AFX_IDW_PANE_FIRST, reposQuery, &ClientRect);

       ClientToScreen(&ClientRect);

      

       // 獲取屏幕的分辨率

       int nFullWidth = GetSystemMetrics(SM_CXSCREEN);

       int nFullHeight = GetSystemMetrics(SM_CYSCREEN);

       // 將出控制條外的客戶區全屏顯示到從(0,0)到(nFullWidth,nFullHeight)區域

       // 將(0,0)和(nFullWidth,nFullHeight)兩個點外擴充原窗口和控制條之外的

       // 客戶區位置間的差值,就得到全屏顯示的窗口位置

       m_FullScreenRect.left = WindowRect.left - ClientRect.left;

       m_FullScreenRect.top = WindowRect.top - ClientRect.top;

       m_FullScreenRect.right = WindowRect.right - ClientRect.right + nFullWidth;

       m_FullScreenRect.bottom = WindowRect.bottom - ClientRect.bottom + nFullHeight;

      

       m_bFullScreen = TRUE;       // 設置全屏顯示標志為TURE

       WINDOWPLACEMENT wndpl;

       wndpl.length = sizeof(WINDOWPLACEMENT);

       wndpl.flags = 0;

       wndpl.showCmd = SW_SHOWNORMAL;

       wndpl.rcNormalPosition = m_FullScreenRect;

       SetWindowPlacement(&wndpl);

}

void CMainFrame::OnUpdateFullScreen(CCmdUI* pCmdUI)

{

       // TODO: Add your command update UI handler code here

       if (m_bFullScreen)

       {

              pCmdUI->SetCheck(1);

       }

       else

       {

              pCmdUI->SetCheck(0);

       }

}

重載CMainFrame類的OnGetMinMaxInfo()函數

void CMainFrame::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI)

{

       // TODO: Add your message handler code here and/or call default

       if (m_bFullScreen)

       {

              lpMMI->ptMaxSize.x = m_FullScreenRect.Width();

              lpMMI->ptMaxSize.y = m_FullScreenRect.Height();

              lpMMI->ptMaxPosition.x = m_FullScreenRect.Width();

              lpMMI->ptMaxPosition.y = m_FullScreenRect.Height();

              //最大的Track尺寸也要改變

              lpMMI->ptMaxTrackSize.x = m_FullScreenRect.Width();

              lpMMI->ptMaxTrackSize.y = m_FullScreenRect.Height();

       }    

       CMDIFrameWnd::OnGetMinMaxInfo(lpMMI);

}

在類CMainFrame中添加函數EndFullScreen()。

void CMainFrame::EndFullScreen()

{

       if (m_bFullScreen)

       {

              // 推出全屏顯示,恢復原始窗口顯示

              ShowWindow(SW_HIDE);

              SetWindowPlacement(&m_OldWndPlacement);

       }

}

下面實現在按下Esc鍵時,調用EndFullScreen()函數。也即:建立按鍵與函數之間的聯系

// 添加WM_KEYDOWN消息相應函數

void CFullScreenTestView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)

{

       // TODO: Add your message handler code here and/or call default

       if (nChar == VK_ESCAPE)   // 如果按下的是Esc鍵

       {

              // 獲取主窗口指針

              CMainFrame* pFrame = (CMainFrame*) AfxGetApp()->m_pMainWnd;

              // 調用主窗口類的自定義函數EndFullScreen(),便可以退出全屏顯示模式

              pFrame->EndFullScreen();

       }

       CView::OnKeyDown(nChar, nRepCnt, nFlags);

}



注意!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系我们删除。



 
  © 2014-2022 ITdaan.com 联系我们: