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

📄 mainfrm.cpp

📁 用VC写的一个将串口数据用图形曲线的形式显示出来。这是一个项目中的一部分。
💻 CPP
字号:
// MainFrm.cpp : implementation of the CMainFrame class
//

#include "stdafx.h"
#include "TestChart.h"
#include "listdialog.h"
#include "MainFrm.h"
#include "testchartview.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_COMMAND(ID_CHART_SHOW, OnChartShow)
	ON_COMMAND(ID_LIST_SHOW, OnListShow)
	//}}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
	
}

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.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)
{
cs.cy = ::GetSystemMetrics(SM_CYSCREEN);
cs.cx = ::GetSystemMetrics(SM_CXSCREEN);

	if( !CFrameWnd::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
{
	CFrameWnd::AssertValid();
}

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

#endif //_DEBUG

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


void CMainFrame::SwitchView(int index)
{
	CView* pOldView=GetActiveView();
	CView* pNewView=(CView*)GetDlgItem(index);

	if(pNewView==NULL)
	{
		switch(index)
		{
		case 1:
			pNewView=(CView*)new CTestChartView;
//			pNewView->OnInitialUpdate();
			break;
		case 2:
			pNewView=(CView*)new CListDialog;
			break;
		}

		CCreateContext context;

		context.m_pCurrentDoc=pOldView->GetDocument();

		pNewView->Create(NULL,NULL,AFX_WS_DEFAULT_VIEW,CFrameWnd::rectDefault,this,index,&context);
	}

	SetActiveView(pNewView);

	pNewView->ShowWindow(SW_SHOW);
	pOldView->ShowWindow(SW_HIDE);

	pOldView->SetDlgCtrlID(AFX_IDW_PANE_FIRST+index);

	pNewView->SetDlgCtrlID(AFX_IDW_PANE_FIRST);

	RecalcLayout();

	delete pOldView;
}



void CMainFrame::OnChartShow() 
{
	// TODO: Add your command handler code here
//	SwitchView(1);
/*	CTestChartView *pChartView =new CTestChartView;
	CListDialog* pListView=new CListDialog;
	pChartView->ShowWindow(SW_SHOW);
	pListView->ShowWindow(SW_HIDE);*/
}

void CMainFrame::OnListShow() 
{
	// TODO: Add your command handler code here
//	SwitchView(2);	
}

BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext) 
{
	m_wndSplitter.CreateStatic(this, 2, 1);
	m_wndSplitter.CreateView(0, 0, pContext->m_pNewViewClass, CSize(100, 250), pContext);
	m_wndSplitter.CreateView(1, 0, RUNTIME_CLASS(CListDialog), CSize(100, 100), pContext);
	SetActiveView((CView*)m_wndSplitter.GetPane(0,0));	
	return true;
}

⌨️ 快捷键说明

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