home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / mfc / database / daoenrol / mainfrm.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-03-27  |  4.7 KB  |  179 lines

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