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