?? mainfrm.cpp
字號:
// MainFrm.cpp : implementation of the CMainFrame class
//
#include "stdafx.h"
#include "SwitchForm.h"
#include "MainFrm.h"
#include "SwitchFormDoc.h"
#include "SwitchFormView.h"
#include "NextFormView.h"
#include "FORMVIEW.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_FIRSTFORM, OnFirstform)
ON_COMMAND(ID_SECONDFORM, OnSecondform)
//}}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)
{
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::SwitchToForm(int nForm)
{
//獲取原來的活動窗體的視圖句柄
CView* pOldActiveView = GetActiveView();
//獲取由"nForm"標識的窗體所對應的視圖句柄
CView* pNewActiveView = (CView*) GetDlgItem(nForm);
//若視圖句柄為空,則創建一新的。
if (pNewActiveView == NULL)
{
if (nForm == IDD_SWITCHFORM_FORM)
pNewActiveView = (CView*)new CSwitchFormView;
if (nForm == IDD_NEXTFORM)
pNewActiveView = (CView*)new CNextFormView;
CCreateContext context;
context.m_pCurrentDoc = pOldActiveView->GetDocument();
pNewActiveView->Create(NULL,NULL,0L,CFrameWnd::rectDefault,this,nForm,&context);
pNewActiveView->OnInitialUpdate();
}
//選擇pNewActiveView為活動窗體
SetActiveView(pNewActiveView);
//顯示活動窗體,隱藏非活動窗體
pNewActiveView->ShowWindow(SW_SHOW);
pOldActiveView->ShowWindow(SW_HIDE);
int ID;
if(pOldActiveView->GetRuntimeClass() == RUNTIME_CLASS(CSwitchFormView))
ID=IDD_SWITCHFORM_FORM;
if(pOldActiveView->GetRuntimeClass() == RUNTIME_CLASS(CNextFormView))
ID=IDD_NEXTFORM;
//設置窗體的ID號
pOldActiveView->SetDlgCtrlID(ID);
pNewActiveView->SetDlgCtrlID(AFX_IDW_PANE_FIRST);
RecalcLayout();
}
void CMainFrame::OnFirstform()
{
// TODO: Add your command handler code here
//通過IsKindOf函數確定當前活動窗口是否是第一個窗口,如是,則無須切換,
//否則將通過SwitchToForm函數將當前活動窗口切換到"IDD_SWITCHFORM_FORM"
//標識的第二個窗體。
if (GetActiveView()->IsKindOf(RUNTIME_CLASS(CSwitchFormView)))
return;
SwitchToForm(IDD_SWITCHFORM_FORM);
}
void CMainFrame::OnSecondform()
{
// TODO: Add your command handler code here
if (GetActiveView()->IsKindOf(RUNTIME_CLASS(CNextFormView)))
return;
SwitchToForm(IDD_NEXTFORM);
}
void CMainFrame::OnUpdateFirstform(CCmdUI *pCmdUI)
{
//通過IsKindOf函數判斷當前活動窗口是否是第一個窗體,如是則將其選中。
pCmdUI->SetCheck(GetActiveView()->IsKindOf(RUNTIME_CLASS(CSwitchFormView)));
}
void CMainFrame::OnUpdateSecondform(CCmdUI *pCmdUI)
{
pCmdUI->SetCheck(GetActiveView()->IsKindOf(RUNTIME_CLASS(CNextFormView)));
}
BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext)
{
// TODO: Add your specialized code here and/or call the base class
CRect rc;
GetClientRect(rc);
m_wndSplitter.CreateStatic(this,1,2);
m_wndSplitter.CreateView(0,0,RUNTIME_CLASS(CNextFormView),CSize(rc.Width()*2/3,rc.Height()),NULL);
m_wndSplitter.CreateView(0,1,RUNTIME_CLASS(CFORMVIEW),CSize(rc.Width()/3,rc.Height()),NULL);
return TRUE;
return CFrameWnd::OnCreateClient(lpcs, pContext);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -