home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c480 / 19.ddi / MFC / SAMPLES / CHKBOOK / MAINFRM.CP_ / MAINFRM.CP
Encoding:
Text File  |  1993-02-08  |  3.6 KB  |  146 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 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 Microsoft
  9. // QuickHelp and/or WinHelp documentation provided with the library.
  10. // See these sources for detailed information regarding the
  11. // Microsoft Foundation Classes product.
  12.  
  13.  
  14. #include "stdafx.h"
  15. #include "chkbook.h"
  16.  
  17. #ifdef _DEBUG
  18. #undef THIS_FILE
  19. static char BASED_CODE THIS_FILE[] = __FILE__;
  20. #endif
  21.  
  22. /////////////////////////////////////////////////////////////////////////////
  23. // CMainFrame
  24.  
  25. IMPLEMENT_DYNAMIC(CMainFrame, CMDIFrameWnd)
  26.  
  27. BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd)
  28.     //{{AFX_MSG_MAP(CMainFrame)
  29.     ON_COMMAND(ID_VIEW_CHECK, OnViewCheck)
  30.     ON_COMMAND(ID_VIEW_BOOK, OnViewBook)
  31.     ON_WM_CREATE()
  32.     ON_WM_CLOSE()
  33.     //}}AFX_MSG_MAP
  34. END_MESSAGE_MAP()
  35.  
  36. /////////////////////////////////////////////////////////////////////////////
  37. // arrays of IDs used to initialize control bars
  38.  
  39. // toolbar buttons - IDs are command buttons
  40. static UINT BASED_CODE buttons[] =
  41. {
  42.     // same order as in the bitmap 'toolbar.bmp'
  43.     ID_EDIT_NEW_CHECK,
  44.     ID_EDIT_COMMIT_CHECK,
  45.         ID_SEPARATOR,
  46.     ID_PREV_CHECK,
  47.     ID_NEXT_CHECK,
  48.         ID_SEPARATOR,
  49.     ID_FILE_PRINT,
  50.     ID_APP_ABOUT,
  51. };
  52.  
  53. static UINT BASED_CODE indicators[] =
  54. {
  55.     ID_SEPARATOR,           // status line indicator
  56.     ID_INDICATOR_CAPS,
  57.     ID_INDICATOR_NUM,
  58.     ID_INDICATOR_SCRL,
  59. };
  60.  
  61. /////////////////////////////////////////////////////////////////////////////
  62. // CMainFrame construction/destruction
  63.  
  64. CMainFrame::CMainFrame()
  65. {
  66. }
  67.  
  68. CMainFrame::~CMainFrame()
  69. {
  70. }
  71.  
  72. int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
  73. {
  74.     if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1)
  75.         return -1;
  76.  
  77.     if (!m_wndToolBar.Create(this) ||
  78.         !m_wndToolBar.LoadBitmap(IDR_MAINFRAME) ||
  79.         !m_wndToolBar.SetButtons(buttons,
  80.           sizeof(buttons)/sizeof(UINT)))
  81.     {
  82.         TRACE("Failed to create toolbar\n");
  83.         return -1;      // fail to create
  84.     }
  85.  
  86.     if (!m_wndStatusBar.Create(this) ||
  87.         !m_wndStatusBar.SetIndicators(indicators,
  88.           sizeof(indicators)/sizeof(UINT)))
  89.     {
  90.         TRACE("Failed to create status bar\n");
  91.         return -1;      // fail to create
  92.     }
  93.  
  94.     return 0;
  95. }
  96.  
  97.  
  98. void CMainFrame::CreateOrActivateFrame(CDocTemplate* pTemplate, 
  99.     CRuntimeClass* pViewClass)
  100. {
  101.     // If a check view or book view (specified by pViewClass)
  102.     // already exists, then activate the MDI child window containing
  103.     // the view.  Otherwise, create a new view for the document.
  104.  
  105.     CMDIChildWnd* pMDIActive = MDIGetActive();
  106.     ASSERT(pMDIActive != NULL);
  107.     CDocument* pDoc = pMDIActive->GetActiveDocument();
  108.     ASSERT(pDoc != NULL);
  109.  
  110.     CView* pView;
  111.     POSITION pos = pDoc->GetFirstViewPosition();
  112.     while (pos)
  113.     {
  114.         pView = pDoc->GetNextView(pos);
  115.         if (pView->IsKindOf(pViewClass))
  116.         {
  117.             pView->GetParentFrame()->ActivateFrame();
  118.             return;
  119.         }
  120.     }
  121.  
  122.     CMDIChildWnd* pNewFrame
  123.         = (CMDIChildWnd*)(pTemplate->CreateNewFrame(pDoc, NULL));
  124.     if (pNewFrame == NULL)
  125.         return;     // not created
  126.     ASSERT(pNewFrame->IsKindOf(RUNTIME_CLASS(CMDIChildWnd)));
  127.     pTemplate->InitialUpdateFrame(pNewFrame, pDoc);
  128.     MDITile(MDITILE_HORIZONTAL);
  129. }
  130.  
  131. /////////////////////////////////////////////////////////////////////////////
  132. // CMainFrame commands
  133.  
  134. void CMainFrame::OnViewCheck()
  135. {
  136.     CreateOrActivateFrame(theApp.m_pCheckViewTemplate, 
  137.         RUNTIME_CLASS(CCheckView));
  138. }
  139.  
  140. void CMainFrame::OnViewBook()
  141. {
  142.     CreateOrActivateFrame(theApp.m_pBookViewTemplate,
  143.         RUNTIME_CLASS(CBookView));
  144. }
  145.  
  146.