www.gusucode.com > VC++动态刷新数据库和多表切换示例-源码程序 > VC++动态刷新数据库和多表切换示例-源码程序/code/mytest/MainFrm.cpp

    //Download by http://www.NewXing.com
// MainFrm.cpp : implementation of the CMainFrame class
//

#include "stdafx.h"
#include "mytest.h"

#include "MainFrm.h"
#include "MytestView.h"
#include "mytestset.h"
#include "zyxxview.h"
#include "zyxxset.h"
#include "dialogfilter.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_ZYXX, OnZyxx)
	ON_UPDATE_COMMAND_UI(ID_ZYXX, OnUpdateZyxx)
	ON_COMMAND(ID_XSDA, OnXsda)
	ON_UPDATE_COMMAND_UI(ID_XSDA, OnUpdateXsda)
	ON_WM_TIMER()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

static UINT indicators[] =
{
	ID_SEPARATOR, // status line indicator
    ID_SEPARATOR,
	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);
  	m_wndStatusBar.SetPaneInfo(1,ID_SEPARATOR,SBPS_NORMAL,100);
    //m_wndStatusBar.SetPaneInfo(2,ID_SEPARATOR,SBPS_NORMAL,100);
   	//m_wndStatusBar.SetPaneInfo(3,ID_SEPARATOR,SBPS_NORMAL,100);
    m_timer=SetTimer(1,1000,NULL);
}

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;
}

/////////////////////////////////////////////////////////////////////////////
// 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::ChangeForm(int nForm)
{
CView* pOldActiveView = GetActiveView();
	CView* pNewActiveView = (CView*)GetDlgItem(nForm);
	if (pNewActiveView == NULL)
	{
		switch (nForm) 
		{
		case IDD_MYTEST_FORM:
			pNewActiveView = (CView*)new CMytestView;
			break;
		case IDD_ZYXX_FORM:
			pNewActiveView = (CView*)new CZyxxView;
			break;
		}
   CCreateContext context;
		context.m_pCurrentDoc = pOldActiveView->GetDocument();
		pNewActiveView->Create(NULL, NULL, 0L, CFrameWnd::rectDefault,
	this, nForm, &context);
	
		pNewActiveView->OnInitialUpdate();
	}
	//显示新切换的视图
	SetActiveView(pNewActiveView);
	pNewActiveView->ShowWindow(SW_SHOW);
	pOldActiveView->ShowWindow(SW_HIDE);
    if (pOldActiveView->GetRuntimeClass()==RUNTIME_CLASS(CMytestView))
			pOldActiveView->SetDlgCtrlID(IDD_MYTEST_FORM);
		else 
			if (pOldActiveView->GetRuntimeClass()==RUNTIME_CLASS(CZyxxView))
				pOldActiveView->SetDlgCtrlID(IDD_ZYXX_FORM);
	pNewActiveView->SetDlgCtrlID(AFX_IDW_PANE_FIRST);
	RecalcLayout();
}

void CMainFrame::OnZyxx() 
{
	// TODO: Add your command handler code here
	ChangeForm(IDD_ZYXX_FORM);
}

void CMainFrame::OnUpdateZyxx(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->SetCheck(GetActiveView()->IsKindOf(RUNTIME_CLASS(CZyxxView)));
}

void CMainFrame::OnXsda() 
{
	// TODO: Add your command handler code here
	ChangeForm(IDD_MYTEST_FORM);
}

void CMainFrame::OnUpdateXsda(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->SetCheck(GetActiveView()->IsKindOf(RUNTIME_CLASS(CMytestView)));
}

void CMainFrame::OnTimer(UINT nIDEvent) 
{
	// TODO: Add your message handler code here and/or call default
	char str[32];
	struct tm *osTime;
	CTime t=CTime::GetCurrentTime();
	osTime=t.GetLocalTm(NULL);

	sprintf(str,"%02d小时%02d分%02d秒",osTime->tm_hour,osTime->tm_min,osTime->tm_sec);
	m_wndStatusBar.SetPaneText(1,str);
	//return 0;
	CFrameWnd::OnTimer(nIDEvent);
}