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

📄 mainfrm.cpp

📁 本程序源码是为日本一家地震监测机构编写的
💻 CPP
字号:
// MainFrm.cpp : implementation of the CMainFrame class
//

#include "stdafx.h"
#include "CQuakeDemo.h"

#include "MainFrm.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CMainFrame

IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)

BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
	//{{AFX_MSG_MAP(CMainFrame)
	ON_WM_CREATE()
	ON_WM_GETMINMAXINFO()
	ON_COMMAND(ID_MENUITEM_FULLSCREEN, OnMenuitemFullscreen)
	ON_UPDATE_COMMAND_UI(ID_MENUITEM_FULLSCREEN, OnUpdateMenuitemFullscreen)
	ON_COMMAND(ID_CANCEL_FULLSCREEN, OnCancelFullscreen)
	ON_COMMAND(ID_QUAKE_CONTROL_BAR, OnQuakeControlBar)
	ON_UPDATE_COMMAND_UI(ID_QUAKE_CONTROL_BAR, OnUpdateQuakeControlBar)
	ON_COMMAND(ID_QUAKE_VIEW_BAR, OnQuakeViewBar)
	ON_UPDATE_COMMAND_UI(ID_QUAKE_VIEW_BAR, OnUpdateQuakeViewBar)
	ON_WM_TIMER()
	//}}AFX_MSG_MAP
	ON_MESSAGE(WM_FULLSCREEN,OnFullScreen)
	ON_MESSAGE(WM_INIINTERFACE,OnIniInterface)
	ON_MESSAGE(WM_STATUSMESSAGE,OnStatusMessage)
END_MESSAGE_MAP()

static UINT indicators[] =
{
	ID_SEPARATOR,           // status line indicator
	ID_INDICATOR_LOAD,
	ID_INDICATOR_CAPS,
	ID_INDICATOR_NUM,
	ID_INDICATOR_SCRL,
};

/////////////////////////////////////////////////////////////////////////////
// CMainFrame construction/destruction

CMainFrame::CMainFrame()
{
	// TODO: add member initialization code here
	
}

CMainFrame::~CMainFrame()
{
}

int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
	if (CFrameWnd::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.CreateStatusBar(this, indicators, sizeof(indicators)/sizeof(UINT)))
	{
		TRACE0("Failed to create status bar\n");
		return -1;      // Fehler beim Erzeugen
	}

    if (!m_ControlBar.Create(_T("Control Bar"), this, CSize(300, 80),
        TRUE, 123))//AFX_IDW_CONTROLBAR_FIRST + 33))
    {
        TRACE0("Failed to create Control Bar\n");
        return -1;      // fail to create
	}
    if (!m_ViewBar.Create(_T("View Bar"), this, CSize(200, 200),
        TRUE, 124))//AFX_IDW_CONTROLBAR_FIRST + 33))
    {
        TRACE0("Failed to create View Bar\n");
        return -1;      // fail to create
	}
	// TODO: Remove this if you don't want tool tips or a resizeable toolbar
	m_wndToolBar.SetBarStyle(m_wndToolBar.GetBarStyle() |
		CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC);

	m_ControlBar.SetBarStyle(m_ControlBar.GetBarStyle() |
		CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC);
	m_ViewBar.SetBarStyle(m_ViewBar.GetBarStyle() |
		CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC);
	// TODO: Delete these three lines if you don't want the toolbar to
	//  be dockable
	m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
	m_ControlBar.EnableDocking(CBRS_ALIGN_TOP|CBRS_ALIGN_BOTTOM);
	m_ViewBar.EnableDocking(CBRS_ALIGN_LEFT|CBRS_ALIGN_RIGHT);
	EnableDocking(CBRS_ALIGN_ANY);
	DockControlBar(&m_wndToolBar);	
	DockControlBar(&m_ControlBar, AFX_IDW_DOCKBAR_BOTTOM);
	DockControlBar(&m_ViewBar,AFX_IDW_DOCKBAR_LEFT);

	m_ControlBar.LoadState(_T("ControlBar"));
	m_ViewBar.LoadState(_T("ViewBar"));
	LoadBarState(_T("ToolBar"));
	
	return 0;
}

BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
	if( !CFrameWnd::PreCreateWindow(cs) )
		return FALSE;
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs
	
	return TRUE;
}

/*void CMainFrame::OnUpdateFrameTitle(BOOL bAddToTitle)
{
//	CString title;
//	title.LoadString(IDS_MAINFRAME_TITLE);
//    SetWindowText(title);
}/**/
/////////////////////////////////////////////////////////////////////////////
// CMainFrame diagnostics

#ifdef _DEBUG
void CMainFrame::AssertValid() const
{
	CFrameWnd::AssertValid();
}

void CMainFrame::Dump(CDumpContext& dc) const
{
	CFrameWnd::Dump(dc);
}

#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CMainFrame message handlers


void CMainFrame::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI) 
{//限制窗体最小为500*500
	CSize sz = FullScreenHandler.GetMaxSize();
	lpMMI->ptMaxSize = CPoint(sz);
	lpMMI->ptMaxTrackSize = CPoint(sz);
	lpMMI->ptMinTrackSize.x = 600;
	lpMMI->ptMinTrackSize.y = 450;
	CFrameWnd::OnGetMinMaxInfo(lpMMI);
}

void CMainFrame::OnMenuitemFullscreen() 
{	
	if (FullScreenHandler.InFullScreenMode())
		FullScreenHandler.Restore(this);
	else 
		FullScreenHandler.Maximize(this, GetActiveView());
}

void CMainFrame::OnUpdateMenuitemFullscreen(CCmdUI* pCmdUI) 
{
	pCmdUI->SetCheck(FullScreenHandler.InFullScreenMode());
}

LRESULT CMainFrame::OnFullScreen(LPARAM lParam, WPARAM wParam)
{
	OnMenuitemFullscreen();
	return NULL;
}

LRESULT CMainFrame::OnIniInterface(LPARAM lParam, WPARAM wParam)
{
	//初始化界面接口对象
	if(m_ControlBar.GetSafeHwnd())
		m_ControlBar.SendMessage(WM_INIINTERFACE,lParam, wParam);
	if(m_ViewBar.GetSafeHwnd())
		m_ViewBar.SendMessage(WM_INIINTERFACE,lParam, wParam);
	return NULL;
}


void CMainFrame::OnCancelFullscreen() 
{
	if (FullScreenHandler.InFullScreenMode())
		FullScreenHandler.Restore(this);
}

BOOL CMainFrame::DestroyWindow() 
{
	m_ControlBar.SaveState(_T("ControlBar"));
	m_ViewBar.SaveState(_T("ViewBar"));
    SaveBarState(_T("ToolBar"));	
	return CFrameWnd::DestroyWindow();
}

void CMainFrame::OnQuakeControlBar() 
{
	BOOL bShow = m_ControlBar.IsVisible();
	ShowControlBar(&m_ControlBar, !bShow, FALSE);	
}

void CMainFrame::OnUpdateQuakeControlBar(CCmdUI* pCmdUI) 
{
	pCmdUI->Enable();
	pCmdUI->SetCheck(m_ControlBar.IsVisible());	
}

void CMainFrame::OnQuakeViewBar() 
{
	BOOL bShow = m_ViewBar.IsVisible();
	ShowControlBar(&m_ViewBar, !bShow, FALSE);	
}

void CMainFrame::OnUpdateQuakeViewBar(CCmdUI* pCmdUI) 
{
	pCmdUI->Enable();
	pCmdUI->SetCheck(m_ViewBar.IsVisible());	
}

//Status Bar Functions//////////////////////////////////////////////////
void CMainFrame::SetLoadText(CString strLoad)
{
	m_wndStatusBar.SetPaneText(m_wndStatusBar.CommandToIndex(ID_INDICATOR_LOAD),strLoad);
}

void CMainFrame::BeginProgress()
{
	m_wndStatusBar.SavePane(0);
	m_wndStatusBar.SetMode(0, XSB_PROGRESS);
}

void CMainFrame::SetRange(int nLower, int nUpper)
{
	m_wndStatusBar.SetRange(0, nLower, nUpper);
}

void CMainFrame::SetPos(int nPos)
{
	m_wndStatusBar.SetPos(0,nPos);
}

void CMainFrame::EndProgress()
{
	m_wndStatusBar.RestorePane(0);
}

LRESULT CMainFrame::OnStatusMessage(LPARAM lParam, WPARAM wParam)
{
	CString strFile, strPic;
	strFile.LoadString(IDS_STRING_LOAD_FILE);
	strPic.LoadString(IDS_STRING_LOAD_PIC);
	switch(lParam)
	{
	case 0:		
		BeginProgress();
		SetRange(0,wParam-1);
		break;
	case 1:
		SetPos(wParam);
		break;
	case 2:
		SetTimer(DelayTimerID,500,0);
		break;
	case 3:
		switch(wParam)
		{
		case 0:SetLoadText(strFile);
			break;
		case 1:SetLoadText(strPic);
			break;
		default:;
		}
		break;
	default:;
	}
	return NULL;
}

void CMainFrame::OnTimer(UINT nIDEvent) 
{
	switch(nIDEvent)
	{
	case DelayTimerID:
		SetLoadText(_T(""));
		EndProgress();
		KillTimer(DelayTimerID);
		break;
	default:;
	}
	CFrameWnd::OnTimer(nIDEvent);
}

⌨️ 快捷键说明

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