MAINFRM.CPP
上传用户:bangxh
上传日期:2007-01-31
资源大小:42235k
文件大小:4k
源码类别:

Windows编程

开发平台:

Visual C++

  1. // MainFrm.cpp : implementation of the CMainFrame class
  2. //
  3. #include "stdafx.h"
  4. #include "Enroll.h"
  5. #include "MainFrm.h"
  6. #include "sectset.h"
  7. #include "coursset.h"
  8. #include "addform.h"
  9. #include "crsform.h"
  10. #include "enroldoc.h"
  11. #include "sectform.h"
  12. #ifdef _DEBUG
  13. #define new DEBUG_NEW
  14. #undef THIS_FILE
  15. static char THIS_FILE[] = __FILE__;
  16. #endif
  17. /////////////////////////////////////////////////////////////////////////////
  18. // CMainFrame
  19. IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)
  20. BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
  21. //{{AFX_MSG_MAP(CMainFrame)
  22. ON_WM_CREATE()
  23. ON_WM_CREATE()
  24. ON_COMMAND(ID_FORM_COURSES, OnFormCourses)
  25. ON_UPDATE_COMMAND_UI(ID_FORM_COURSES, OnUpdateFormCourses)
  26. ON_COMMAND(ID_FORM_SECTIONS, OnFormSections)
  27. ON_UPDATE_COMMAND_UI(ID_FORM_SECTIONS, OnUpdateFormSections)
  28. //}}AFX_MSG_MAP
  29. END_MESSAGE_MAP()
  30. static UINT indicators[] =
  31. {
  32. ID_SEPARATOR,           // status line indicator
  33. ID_INDICATOR_CAPS,
  34. ID_INDICATOR_NUM,
  35. ID_INDICATOR_SCRL,
  36. };
  37. /////////////////////////////////////////////////////////////////////////////
  38. // CMainFrame construction/destruction
  39. CMainFrame::CMainFrame()
  40. {
  41. // TODO: add member initialization code here
  42. }
  43. CMainFrame::~CMainFrame()
  44. {
  45. }
  46. int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
  47. {
  48. if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
  49. return -1;
  50. if (!m_wndToolBar.Create(this) ||
  51. !m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
  52. {
  53. TRACE0("Failed to create toolbarn");
  54. return -1;      // fail to create
  55. }
  56. if (!m_wndStatusBar.Create(this) ||
  57. !m_wndStatusBar.SetIndicators(indicators,
  58.   sizeof(indicators)/sizeof(UINT)))
  59. {
  60. TRACE0("Failed to create status barn");
  61. return -1;      // fail to create
  62. }
  63. // TODO: Remove this if you don't want tool tips
  64. m_wndToolBar.SetBarStyle(m_wndToolBar.GetBarStyle() |
  65. CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC);
  66. // TODO: Delete these three lines if you don't want the toolbar to
  67. //  be dockable
  68. m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
  69. EnableDocking(CBRS_ALIGN_ANY);
  70. DockControlBar(&m_wndToolBar);
  71. return 0;
  72. }
  73. BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
  74. {
  75. // TODO: Modify the Window class or styles here by modifying
  76. //  the CREATESTRUCT cs
  77. return CFrameWnd::PreCreateWindow(cs);
  78. }
  79. void CMainFrame::SwitchToForm(int nForm)
  80. {
  81. CView* pOldActiveView = GetActiveView();
  82. CView* pNewActiveView = (CView*)GetDlgItem(nForm);
  83. if (pNewActiveView == NULL)
  84. {
  85. if (nForm == IDW_COURSE_FORM)
  86. pNewActiveView = (CView*)new CCourseForm;
  87. else
  88. pNewActiveView = (CView*)new CSectionForm;
  89. CCreateContext context;
  90. context.m_pCurrentDoc = pOldActiveView->GetDocument();
  91. pNewActiveView->Create(NULL, NULL, 0L, CFrameWnd::rectDefault,
  92. this, nForm, &context);
  93. pNewActiveView->OnInitialUpdate();
  94. }
  95. SetActiveView(pNewActiveView);
  96. pNewActiveView->ShowWindow(SW_SHOW);
  97. pOldActiveView->ShowWindow(SW_HIDE);
  98. pOldActiveView->SetDlgCtrlID(
  99. pOldActiveView->GetRuntimeClass() == RUNTIME_CLASS(CCourseForm) ?
  100. IDW_COURSE_FORM : IDW_SECTION_FORM);
  101. pNewActiveView->SetDlgCtrlID(AFX_IDW_PANE_FIRST);
  102. RecalcLayout();
  103. }
  104. /////////////////////////////////////////////////////////////////////////////
  105. // CMainFrame diagnostics
  106. #ifdef _DEBUG
  107. void CMainFrame::AssertValid() const
  108. {
  109. CFrameWnd::AssertValid();
  110. }
  111. void CMainFrame::Dump(CDumpContext& dc) const
  112. {
  113. CFrameWnd::Dump(dc);
  114. }
  115. #endif //_DEBUG
  116. /////////////////////////////////////////////////////////////////////////////
  117. // CMainFrame message handlers
  118. void CMainFrame::OnFormCourses()
  119. {
  120. if (GetActiveView()->IsKindOf(RUNTIME_CLASS(CCourseForm)))
  121. return; // already active
  122. SwitchToForm(IDW_COURSE_FORM);
  123. }
  124. void CMainFrame::OnUpdateFormCourses(CCmdUI* pCmdUI)
  125. {
  126. pCmdUI->SetCheck(GetActiveView()->IsKindOf(RUNTIME_CLASS(CCourseForm)));
  127. }
  128. void CMainFrame::OnFormSections()
  129. {
  130. if (GetActiveView()->IsKindOf(RUNTIME_CLASS(CSectionForm)))
  131. return; // already active
  132. SwitchToForm(IDW_SECTION_FORM);
  133. }
  134. void CMainFrame::OnUpdateFormSections(CCmdUI* pCmdUI)
  135. {
  136. pCmdUI->SetCheck(GetActiveView()->IsKindOf(RUNTIME_CLASS(CSectionForm)));
  137. }