MFC 控件全屏显示

版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/sea310/article/details/7676867

最近在做基于对话框的简易播放器,其中涉及用于显示图像的picture 控件全屏的问题,综合csdn各个帖子,凑合完成了全屏显示。


//全屏显示

//成员变量
BOOL            m_bFullScreen;     // 全屏标志
CRect           m_FullScreenRect;  // 整个屏幕尺寸
WINDOWPLACEMENT m_OldWndPlacement; // 全屏时对话框的位置属性
WINDOWPLACEMENT m_NewWndPlacement; // 全屏后对话框的位置属性

//成员函数
1.
void CMyplayerDlg::OnFullShow()
{
    // TODO: Add your command handler code here

    if ((TRUE == m_bOpen) && (FALSE == m_bFullScreen))
    {
        m_bFullScreen = TRUE;

        //获取对话框原始位置
        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);

        //对话框全屏显示
        m_FullScreenRect.left = WindowRect.left - ClientRect.left;
        int m_top = WindowRect.top - ClientRect.top;
        m_FullScreenRect.top    = m_top;
        m_FullScreenRect.right  = WindowRect.right - ClientRect.right + nFullWidth;
        m_FullScreenRect.bottom = WindowRect.bottom - ClientRect.bottom + nFullHeight;

        m_NewWndPlacement.length           = sizeof(WINDOWPLACEMENT);
        m_NewWndPlacement.flags            = 0;
        m_NewWndPlacement.showCmd          = SW_SHOWNORMAL;
        m_NewWndPlacement.rcNormalPosition = m_FullScreenRect;
        SetWindowPlacement(&m_NewWndPlacement);

        //Picture控件全屏显示
        pWnd->MoveWindow(CRect(0, 0, nFullWidth, nFullHeight));

        //隐藏控件
        GetDlgItem(IDC_PLAY)->ShowWindow(SW_HIDE);
        
    }
}
2.
void CMyplayerDlg::NormalShow(void)
{
    if ((TRUE == m_bOpen) && (TRUE == m_bFullScreen))
    {
        //恢复默认窗口
        SetWindowPlacement(&m_OldWndPlacement);

        m_bFullScreen = FALSE;

        //显示控件
        GetDlgItem(IDC_PLAY)->ShowWindow(SW_SHOW);
       
    }
}
3.
void CMyplayerDlg::OnGetMinMaxInfo(MINMAXINFO *lpMMI)
{
    // TODO: Add your message handler code here and/or call default
    if (TRUE == 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();
    }
    CDialog::OnGetMinMaxInfo(lpMMI);
}
4.
BOOL CMyplayerDlg::PreTranslateMessage(MSG *pMsg)
{
    if (TRUE == m_bOpen)
    {
        if (WM_LBUTTONDBLCLK == pMsg->message) // 1 鼠标双击响应
        {
			//获取鼠标位置
            CPoint ptCursor;
            GetCursorPos(&ptCursor);

            CRect rc;
            GetDlgItem(IDC_SHOW_IMAGE)->GetWindowRect(&rc);

            //1.1 双击时鼠标位于Picture控件范围内才响应
            if (rc.PtInRect(ptCursor))
            {
                if (FALSE == m_bFullScreen)
                {
                    OnFullShow(); //全屏显示
                }
                else
                {
                    NormalShow();  //恢复默认显示
                }
            }
        } //end of if (WM_LBUTTONDBLCLK == pMsg->message)
        else if (WM_KEYDOWN == pMsg->message) // 2 键盘输入响应
        {
            // 2.1键盘输入Esc
            if (VK_ESCAPE == pMsg->wParam)
            {
				if (TRUE == m_bFullScreen)
				{
					NormalShow();  //恢复默认显示
				}                
            }

            // 2.2键盘输入Enter
            if (VK_RETURN == pMsg->wParam)
            {
                if (FALSE == m_bFullScreen)
                {
                    OnFullShow(); //全屏显示
                }
                else
                {
                    NormalShow();  //恢复默认显示
                }
            }
        } //end of if (WM_KEYDOWN == pMsg->message)
    } // end of if (TRUE == m_bOpen)

    return 0;
}




展开阅读全文

没有更多推荐了,返回首页