home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / mfc / tutorial / enroll / step4 / mainfrm.cpp < prev    next >
C/C++ Source or Header  |  1998-03-26  |  4KB  |  172 lines

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