MFC 对话框全屏显示

新建MFC对话框应用程序

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

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

	CDialog::OnRButtonDown(nFlags, point);
}


展开阅读全文

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