www.pudn.com > FullScreen.rar > MainFrm.cpp, change:2010-10-16,size:3952b


// MainFrm.cpp : implementation of the CMainFrame class 
// 
 
#include "stdafx.h" 
#include "FullScreen.h" 
 
#include "MainFrm.h" 
 
#ifdef _DEBUG 
#define new DEBUG_NEW 
#undef THIS_FILE 
static char THIS_FILE[] = __FILE__; 
#endif 
 
///////////////////////////////////////////////////////////////////////////// 
// CMainFrame 
 
IMPLEMENT_DYNAMIC(CMainFrame, CMDIFrameWnd) 
 
BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd) 
	//{{AFX_MSG_MAP(CMainFrame) 
	ON_WM_CREATE() 
	ON_WM_GETMINMAXINFO() 
	//}}AFX_MSG_MAP 
END_MESSAGE_MAP() 
 
static UINT indicators[] = 
{ 
	ID_SEPARATOR,           // status line indicator 
	ID_INDICATOR_CAPS, 
	ID_INDICATOR_NUM, 
	ID_INDICATOR_SCRL, 
}; 
 
///////////////////////////////////////////////////////////////////////////// 
// CMainFrame construction/destruction 
 
CMainFrame::CMainFrame() 
{ 
	// TODO: add member initialization code here 
	m_isFull = false; 
} 
 
CMainFrame::~CMainFrame() 
{ 
} 
 
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{ 
	if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1) 
		return -1; 
	 
	if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP 
		| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) || 
		!m_wndToolBar.LoadToolBar(IDR_MAINFRAME)) 
	{ 
		TRACE0("Failed to create toolbar\n"); 
		return -1;      // fail to create 
	} 
 
	if (!m_wndStatusBar.Create(this) || 
		!m_wndStatusBar.SetIndicators(indicators, 
		  sizeof(indicators)/sizeof(UINT))) 
	{ 
		TRACE0("Failed to create status bar\n"); 
		return -1;      // fail to create 
	} 
 
	// TODO: Delete these three lines if you don't want the toolbar to 
	//  be dockable 
	m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY); 
	EnableDocking(CBRS_ALIGN_ANY); 
	DockControlBar(&m_wndToolBar); 
 
	return 0; 
} 
 
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs) 
{ 
	if( !CMDIFrameWnd::PreCreateWindow(cs) ) 
		return FALSE; 
	// TODO: Modify the Window class or styles here by modifying 
	//  the CREATESTRUCT cs 
 
	return TRUE; 
} 
 
///////////////////////////////////////////////////////////////////////////// 
// CMainFrame diagnostics 
 
#ifdef _DEBUG 
void CMainFrame::AssertValid() const 
{ 
	CMDIFrameWnd::AssertValid(); 
} 
 
void CMainFrame::Dump(CDumpContext& dc) const 
{ 
	CMDIFrameWnd::Dump(dc); 
} 
 
#endif //_DEBUG 
 
///////////////////////////////////////////////////////////////////////////// 
// CMainFrame message handlers 
 
 
void CMainFrame::FullScreen() 
{ 
	GetWindowPlacement(&m_oldPos);	// 得到当前窗口的位置 
	CRect winRect;						// 窗口区域 
	GetWindowRect(&winRect);			// 得到窗口区域 
	CRect rectClient; 
	RepositionBars(0, 0xffff, AFX_IDW_PANE_FIRST, reposQuery, &rectClient); // 全屏时隐藏所有的控制条 
	ClientToScreen(&rectClient);		// 将客户坐标映射成屏幕坐标 
 
	//获取屏幕分辨率 
	int fullWidth  = GetSystemMetrics(SM_CXSCREEN); 
	int fullHeight = GetSystemMetrics(SM_CYSCREEN); 
     
	//得到全屏显示的窗口位置  
	m_fullScreenRect.left  = winRect.left   - rectClient.left; 
	m_fullScreenRect.top   = winRect.top    - rectClient.top; 
	m_fullScreenRect.right = winRect.right  - rectClient.right  + fullWidth; 
	m_fullScreenRect.bottom= winRect.bottom - rectClient.bottom + fullHeight; 
	 
	// 进入全屏显示状态 
	m_isFull = TRUE;	// 设置全屏标志 
	WINDOWPLACEMENT tmp;		 
	tmp.length  = sizeof(WINDOWPLACEMENT); 
	tmp.flags   = 0; 
	tmp.showCmd = SW_SHOWNORMAL; 
	tmp.rcNormalPosition = m_fullScreenRect; 
	SetWindowPlacement(&tmp);	// 将窗口设置到m_fullScreenRect位置上 
} 
 
void CMainFrame::noFullScreen() 
{ 
	if(m_isFull) 
	{ 
		m_isFull = FALSE;			// 设置全屏状态为FALSE 
		SetWindowPlacement(&m_oldPos);	// 退出全屏显示, 恢复原窗口显示 
	} 
} 
 
void CMainFrame::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI)  
{ 
	if(m_isFull)  
	{ 
		lpMMI->ptMaxTrackSize.x = m_fullScreenRect.Width();		//设置最大跟踪宽度 
		lpMMI->ptMaxTrackSize.y = m_fullScreenRect.Height();	//设置最大跟踪高度 
	}  
	CMDIFrameWnd::OnGetMinMaxInfo(lpMMI); 
}