home *** CD-ROM | disk | FTP | other *** search
/ Mastering MFC Development / MMD.ISO / samples / c07 / mdi2viewsb / mainfrm.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1997-02-20  |  3.8 KB  |  154 lines

  1. // MainFrm.cpp : implementation of the CMainFrame class
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "MDI2ViewsB.h"
  6.  
  7. #include "MainFrm.h"
  8.  
  9. #ifdef _DEBUG
  10. #define new DEBUG_NEW
  11. #undef THIS_FILE
  12. static char THIS_FILE[] = __FILE__;
  13. #endif
  14.  
  15. /////////////////////////////////////////////////////////////////////////////
  16. // CMainFrame
  17.  
  18. IMPLEMENT_DYNAMIC(CMainFrame, CMDIFrameWnd)
  19.  
  20. BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd)
  21.     //{{AFX_MSG_MAP(CMainFrame)
  22.         // NOTE - the ClassWizard will add and remove mapping macros here.
  23.         //    DO NOT EDIT what you see in these blocks of generated code !
  24.     ON_WM_CREATE()
  25.     ON_COMMAND(ID_WINDOW_ITALICS, OnWindowItalics)
  26.     ON_COMMAND(ID_WINDOW_NEW, OnWindowItalics)
  27.     //}}AFX_MSG_MAP
  28. END_MESSAGE_MAP()
  29.  
  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. /////////////////////////////////////////////////////////////////////////////
  39. // CMainFrame construction/destruction
  40.  
  41. CMainFrame::CMainFrame()
  42. {
  43.     // TODO: add member initialization code here
  44.     
  45. }
  46.  
  47. CMainFrame::~CMainFrame()
  48. {
  49. }
  50.  
  51. int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
  52. {
  53.     if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1)
  54.         return -1;
  55.     
  56.     if (!m_wndToolBar.Create(this) ||
  57.         !m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
  58.     {
  59.         TRACE0("Failed to create toolbar\n");
  60.         return -1;      // fail to create
  61.     }
  62.  
  63.     if (!m_wndStatusBar.Create(this) ||
  64.         !m_wndStatusBar.SetIndicators(indicators,
  65.           sizeof(indicators)/sizeof(UINT)))
  66.     {
  67.         TRACE0("Failed to create status bar\n");
  68.         return -1;      // fail to create
  69.     }
  70.  
  71.     // TODO: Remove this if you don't want tool tips or a resizeable toolbar
  72.     m_wndToolBar.SetBarStyle(m_wndToolBar.GetBarStyle() |
  73.         CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC);
  74.  
  75.     // TODO: Delete these three lines if you don't want the toolbar to
  76.     //  be dockable
  77.     m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
  78.     EnableDocking(CBRS_ALIGN_ANY);
  79.     DockControlBar(&m_wndToolBar);
  80.  
  81.     return 0;
  82. }
  83.  
  84. BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
  85. {
  86.     // TODO: Modify the Window class or styles here by modifying
  87.     //  the CREATESTRUCT cs
  88.  
  89.     return CMDIFrameWnd::PreCreateWindow(cs);
  90. }
  91.  
  92. /////////////////////////////////////////////////////////////////////////////
  93. // CMainFrame diagnostics
  94.  
  95. #ifdef _DEBUG
  96. void CMainFrame::AssertValid() const
  97. {
  98.     CMDIFrameWnd::AssertValid();
  99. }
  100.  
  101. void CMainFrame::Dump(CDumpContext& dc) const
  102. {
  103.     CMDIFrameWnd::Dump(dc);
  104. }
  105.  
  106. #endif //_DEBUG
  107.  
  108. /////////////////////////////////////////////////////////////////////////////
  109. // CMainFrame message handlers
  110. void CMainFrame::OnWindowItalics() 
  111. {
  112.     // We'll need a pointer to the active child...
  113.     CMDIChildWnd* pChild = MDIGetActive();
  114.     if (NULL == pChild)
  115.     {
  116.         TRACE0("Warning: No active child.\n");
  117.         AfxMessageBox(AFX_IDP_COMMAND_FAILURE);
  118.         return;     // command failed
  119.     }
  120.     
  121.     // and to the active document...
  122.     CDocument* pDoc = pChild->GetActiveDocument();
  123.     if (NULL == pDoc)
  124.     {
  125.         TRACE0("Warning: No active document.\n");
  126.         AfxMessageBox(AFX_IDP_COMMAND_FAILURE);
  127.         return;     // command failed
  128.     }
  129.  
  130.     // and to the application object.
  131.     CMDI2ViewsBApp * pApp = (CMDI2ViewsBApp *)AfxGetApp();
  132.  
  133.     // Since both menu selections end up here (see message map)
  134.     MSG const * pMsg = GetCurrentMessage();
  135.     CMultiDocTemplate * pTemplate;
  136.  
  137.     // we need to know how we got here to figure out which template to use...
  138.     if (LOWORD(pMsg->wParam) == ID_WINDOW_ITALICS)
  139.         pTemplate = pApp->m_pItalicsTemplate;
  140.     else
  141.         pTemplate = pApp->m_pDefaultTemplate;
  142.  
  143.     // so that finally we can create a new frame...
  144.     CFrameWnd* pFrame = pTemplate->CreateNewFrame(pDoc, pChild);
  145.     if (NULL == pFrame)
  146.     {
  147.         TRACE0("Warning: failed to create new frame.\n");
  148.         return;     // command failed
  149.     }
  150.  
  151.     // which is then updated.
  152.     pTemplate->InitialUpdateFrame(pFrame, pDoc);
  153. }
  154.