📄 mainfrm.cpp
字号:
// MainFrm.cpp : implementation of the CMainFrame class
//
#include "stdafx.h"
#include "MyStudent.h"
#include "PrintView.h"
//#include "MyStudentView.h"
#include "MyStudentDoc.h"
#include "MainFrm.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
//定义各个视图代号
#define ID_MAINCONTROL 1
#define ID_CLASS 2
#define ID_CLASSES 3
/////////////////////////////////////////////////////////////////////////////
// CMainFrame
IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)
BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
//{{AFX_MSG_MAP(CMainFrame)
ON_WM_CREATE()
ON_COMMAND(ID_VIEW_CLASS, OnViewClass)
ON_COMMAND(ID_VIEW_CLASSES, OnViewClasses)
ON_COMMAND(ID_VIEW_MAIN_CONTROL, OnViewMainControl)
ON_UPDATE_COMMAND_UI(ID_VIEW_CLASS, OnUpdateViewClass)
ON_UPDATE_COMMAND_UI(ID_VIEW_CLASSES, OnUpdateViewClasses)
ON_UPDATE_COMMAND_UI(ID_VIEW_MAIN_CONTROL, OnUpdateViewMainControl)
//}}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()
{
}
CMainFrame::~CMainFrame()
{
}
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
m_current_view=1;
m_mainview=NULL;
m_printview=NULL;
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
}
m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
EnableDocking(CBRS_ALIGN_ANY);
DockControlBar(&m_wndToolBar);
return 0;
}
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
cs.cx=590;
cs.cy=495;
cs.x=(GetSystemMetrics(SM_CXSCREEN)-cs.cx)/2;
cs.y=(GetSystemMetrics(SM_CYSCREEN)-cs.cy)/2;
return CFrameWnd::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// 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::OnViewClass()
{
// TODO: Add your command handler code here
m_current_view=ID_CLASS;
SwitchToForm(m_current_view);
}
void CMainFrame::OnViewClasses()
{
// TODO: Add your command handler code here
m_current_view=ID_CLASSES;
SwitchToForm(m_current_view);
}
void CMainFrame::OnViewMainControl()
{
// TODO: Add your command handler code here
m_current_view=ID_MAINCONTROL;
SwitchToForm(m_current_view);
}
//==============================================================
void CMainFrame::SwitchToForm(int nForm) //进行视图切换的代码函数
{
CMyStudentDoc* pDoc = (CMyStudentDoc*)GetActiveDocument();
CString tempstr;
//GetWindowText(tempstr);
tempstr=pDoc->m_database;
//----------------------------------------------------
//----------------在第一次要切换视图时创建视图--------
if(m_mainview==NULL)
m_mainview=GetActiveView();//给主视图指针赋一次值
if(m_printview==NULL)
{
m_printview=(CView*)new CPrintView;
CCreateContext newcontext;//将文挡和视图相连
newcontext.m_pCurrentDoc=GetActiveDocument();
m_printview->Create(NULL, NULL, WS_BORDER|WS_CHILD,
CFrameWnd::rectDefault, this, 0, &newcontext);
m_printview->OnInitialUpdate();//对于这样创建的视图。必须这样初始化。
}
//------------------------------------------------------
CView* pNewActiveView;
CView* pOldActiveView;
if(nForm==ID_MAINCONTROL)
{
pNewActiveView=m_mainview;
pOldActiveView=m_printview;
SetWindowText(_T(tempstr+"->主控制界面"));
}
else if(nForm==ID_CLASS)
{
pNewActiveView=m_printview;
pOldActiveView=m_mainview;
((CPrintView*)m_printview)->m_tagview=0;
SetWindowText(_T(tempstr+"->分班级进行浏览,打印视图"));
}
else if(nForm==ID_CLASSES)
{
pNewActiveView=m_printview;
pOldActiveView=m_mainview;
((CPrintView*)m_printview)->m_tagview=1;
SetWindowText(_T(tempstr+"->按全部班级进行浏览,打印视图"));
}
else
{
return;
}
SetActiveView(pNewActiveView); //改变活动的视图
pNewActiveView->ShowWindow(SW_SHOW); //显示新的视图
pOldActiveView->ShowWindow(SW_HIDE); //隐藏旧的视图
pNewActiveView->Invalidate(TRUE); //使客户区失效,OnInitUpdate();
pNewActiveView->UpdateData(FALSE); //更新对话框数据显示
pOldActiveView->SetDlgCtrlID(AFX_IDW_PANE_FIRST+1); //隐藏旧的视图
pNewActiveView->SetDlgCtrlID(AFX_IDW_PANE_FIRST);//很重要。为什么?
RecalcLayout(); //调整框架窗口
}
//======================================================================
//======================================================================
void CMainFrame::OnUpdateViewClass(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->SetCheck(m_current_view==ID_CLASS);
}
void CMainFrame::OnUpdateViewClasses(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->SetCheck(m_current_view==ID_CLASSES);
}
void CMainFrame::OnUpdateViewMainControl(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->SetCheck(m_current_view==ID_MAINCONTROL);
}
//=======================================================================
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -