MFC对话框全屏显示代码[亲测可用]

新建MFC对话框应用程序

在FullTestDlg.h : 头文件添加变量

private:

BOOL bFullScreen;

WINDOWPLACEMENT m_struOldWndpl;

private:
	BOOL bFullScreen;
	WINDOWPLACEMENT m_struOldWndpl;

// FullTestDlg.cpp : 实现文件

void CFullTestDlg::OnBnClickedButtonFull()
{
//MessageBox(_T(“测试”));




int iShowStat = bFullScreen?SW_HIDE:SW_SHOW;


if (!bFullScreen)
{
//get current system resolution
int g_iCurScreenWidth = GetSystemMetrics(SM_CXSCREEN);
int g_iCurScreenHeight = GetSystemMetrics(SM_CYSCREEN);


//for full screen while backplay
GetWindowPlacement(&m_struOldWndpl);


CRect rectWholeDlg;//entire client(including title bar)
CRect rectClient;//client area(not including title bar)
CRect rectFullScreen;
GetWindowRect(&rectWholeDlg);
RepositionBars(0, 0xffff, AFX_IDW_PANE_FIRST, reposQuery, &rectClient);
ClientToScreen(&rectClient);


rectFullScreen.left = rectWholeDlg.left-rectClient.left;
rectFullScreen.top = rectWholeDlg.top-rectClient.top;
rectFullScreen.right = rectWholeDlg.right+g_iCurScreenWidth – rectClient.right;
rectFullScreen.bottom = rectWholeDlg.bottom+g_iCurScreenHeight – rectClient.bottom;
//enter into full screen;
WINDOWPLACEMENT struWndpl;
struWndpl.length = sizeof(WINDOWPLACEMENT);
struWndpl.flags = 0;
struWndpl.showCmd = SW_SHOWNORMAL;
struWndpl.rcNormalPosition = rectFullScreen;
SetWindowPlacement(&struWndpl);

bFullScreen=true;
}


}

void CFullTestDlg::OnBnClickedButtonFull()
{
	//MessageBox(_T("测试"));


	int iShowStat = bFullScreen?SW_HIDE:SW_SHOW;

	if (!bFullScreen)
	{
		//get current system resolution
		int g_iCurScreenWidth = GetSystemMetrics(SM_CXSCREEN);
		int g_iCurScreenHeight = GetSystemMetrics(SM_CYSCREEN);

		//for full screen while backplay
		GetWindowPlacement(&m_struOldWndpl);

		CRect rectWholeDlg;//entire client(including title bar)
		CRect rectClient;//client area(not including title bar)
		CRect rectFullScreen;
		GetWindowRect(&rectWholeDlg);
		RepositionBars(0, 0xffff, AFX_IDW_PANE_FIRST, reposQuery, &rectClient);
		ClientToScreen(&rectClient);

		rectFullScreen.left = rectWholeDlg.left-rectClient.left;
		rectFullScreen.top = rectWholeDlg.top-rectClient.top;
		rectFullScreen.right = rectWholeDlg.right+g_iCurScreenWidth - rectClient.right;
		rectFullScreen.bottom = rectWholeDlg.bottom+g_iCurScreenHeight - rectClient.bottom;
		//enter into full screen;
		WINDOWPLACEMENT struWndpl;
		struWndpl.length = sizeof(WINDOWPLACEMENT);
		struWndpl.flags = 0;
		struWndpl.showCmd = SW_SHOWNORMAL;
		struWndpl.rcNormalPosition = rectFullScreen;
		SetWindowPlacement(&struWndpl);
		
		bFullScreen=true;
	}

}

增加右键消息处理函数,退出全屏模式

void CFullTestDlg::OnRButtonDown(UINT nFlags, CPoint point)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
if(bFullScreen){
SetWindowPlacement(&m_struOldWndpl);
bFullScreen=false;
}


CDialog::OnRButtonDown(nFlags, point);
}

    原文作者:小魏的马仔
    原文地址: https://blog.csdn.net/xuexiiphone/article/details/51252766
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞