⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mainfrm.cpp

📁 《VC++ 编程技巧与示例 .rar》各个示例代码绝对可用
💻 CPP
字号:
// MainFrm.cpp : implementation of the CMainFrame class
//

#include "stdafx.h"
#include "FULLSCRTest.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_COMMAND(ID_FULL_SCREEN, OnFullScreen)
	//}}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_bIsFullScreen=FALSE;
	m_bToolbarVisible=TRUE;
	m_bStatusbarVisible=TRUE;
}

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::OnFullScreen() 
{
	// TODO: Add your command handler code here
	// if the view is now full screen, change the view to normal size and state	
	if (m_bIsFullScreen) 
	{
		// add the WS_CAPTION and WS_THICKFRAME styles to the frame window		
		ModifyStyle(0,WS_CAPTION);			
		ModifyStyle(0,WS_THICKFRAME);

		// restore the frame window to normal size and state
		ShowWindow(SW_SHOWNORMAL);

		CRect rc;
		GetClientRect(&rc);
		
		rc.bottom=rc.top+rc.Height()/2;
		CFrameWnd * pFrame;
		pFrame=GetActiveFrame();
		pFrame->ModifyStyle(0,WS_CAPTION);
		pFrame->ModifyStyle(0,WS_THICKFRAME);
		pFrame->ModifyStyle(0,WS_MINIMIZEBOX|WS_MAXIMIZEBOX);
		pFrame->MoveWindow(rc);

		// restore the default menu and show it
		SetMenu(&m_Menu);
		m_Menu.Detach();

		//re show the toolbars
		ShowControlBar(&m_wndToolBar, m_bToolbarVisible, FALSE);
		ShowControlBar(&m_wndStatusBar, m_bStatusbarVisible, FALSE);
		// set flag to indicate that frame window is now NOT full screen
		m_bIsFullScreen = 0;		
	}
		// if the view is now normal, change the view to full screen		
	else 
	{
	    //remember each of the controlbars visibility before we hide them
	    CFrameWnd* pFrame = GetActiveFrame();
		if(pFrame==this)
		{
			return;
		}
	    m_bToolbarVisible = ((m_wndToolBar.GetStyle() & WS_VISIBLE) != 0);
	    m_bStatusbarVisible = ((m_wndStatusBar.GetStyle() & WS_VISIBLE) != 0);
	    m_Menu.Attach(GetMenu()->m_hMenu);

		// remove the WS_CAPTION and WS_THICKFRAME styles from the frame window
		ModifyStyle(WS_CAPTION,0);			
	    ModifyStyle(WS_THICKFRAME,0);
		// remove the default menu and erase the menu			
		SetMenu(NULL);
		// show the now menuless and frameless window full screen
		ShowWindow(SW_MAXIMIZE);

		ShowControlBar(&m_wndToolBar, FALSE, FALSE);
		ShowControlBar(&m_wndStatusBar, FALSE, FALSE);

		CRect rc;
		GetClientRect(&rc);
	    if (pFrame)
		{
			pFrame->ModifyStyle(WS_CAPTION,0);			
			pFrame->ModifyStyle(WS_THICKFRAME,0);
			pFrame->MoveWindow(rc);
		}
		//reset the flag to indicate that the view is now full screen
			m_bIsFullScreen = 1;		
	}
}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -