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

  1. // mainfrm.cpp
  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. // Purpose: implementation of the CMainFrame class
  14. //
  15. // Functions:
  16. //      Most of this file was generated by AppWizard.  The functions
  17. //      which contain code specific to this sample are:
  18. //
  19. //      CMainFrame::GetMessageString()   -- override of CFrameWnd::GetMessageString
  20. //                                          to customize message on status bar
  21.  
  22. #include "stdafx.h"
  23. #include "dynamenu.h"
  24.  
  25. #include "mainfrm.h"
  26. #include "dmdoc.h"    // for color definitions
  27.  
  28. #ifdef _DEBUG
  29. #undef THIS_FILE
  30. static char BASED_CODE THIS_FILE[] = __FILE__;
  31. #endif
  32.  
  33. /////////////////////////////////////////////////////////////////////////////
  34. // CMainFrame
  35.  
  36. IMPLEMENT_DYNAMIC(CMainFrame, CMDIFrameWnd)
  37.  
  38. BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd)
  39.     //{{AFX_MSG_MAP(CMainFrame)
  40.     ON_WM_CREATE()
  41.     //}}AFX_MSG_MAP
  42. END_MESSAGE_MAP()
  43.  
  44. /////////////////////////////////////////////////////////////////////////////
  45. // arrays of IDs used to initialize control bars
  46.  
  47. // toolbar buttons - IDs are command buttons
  48. static UINT BASED_CODE buttons[] =
  49. {
  50.     // same order as in the bitmap 'toolbar.bmp'
  51.     ID_FILE_NEW,
  52.     ID_FILE_OPEN,
  53.     ID_FILE_SAVE,
  54.         ID_SEPARATOR,
  55.     ID_EDIT_CUT,
  56.     ID_EDIT_COPY,
  57.     ID_EDIT_PASTE,
  58.         ID_SEPARATOR,
  59.     ID_FILE_PRINT,
  60.     ID_APP_ABOUT,
  61. };
  62.  
  63. static UINT BASED_CODE indicators[] =
  64. {
  65.     ID_SEPARATOR,           // status line indicator
  66.     ID_INDICATOR_CAPS,
  67.     ID_INDICATOR_NUM,
  68.     ID_INDICATOR_SCRL,
  69. };
  70.  
  71. /////////////////////////////////////////////////////////////////////////////
  72. // CMainFrame construction/destruction
  73.  
  74. CMainFrame::CMainFrame()
  75. {
  76.     // TODO: add member initialization code here
  77. }
  78.  
  79. CMainFrame::~CMainFrame()
  80. {
  81. }
  82.  
  83. int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
  84. {
  85.     if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1)
  86.         return -1;
  87.  
  88.     if (!m_wndToolBar.Create(this) ||
  89.         !m_wndToolBar.LoadBitmap(IDR_MAINFRAME) ||
  90.         !m_wndToolBar.SetButtons(buttons,
  91.           sizeof(buttons)/sizeof(UINT)))
  92.     {
  93.         TRACE0("Failed to create toolbar\n");
  94.         return -1;      // fail to create
  95.     }
  96.  
  97.     if (!m_wndStatusBar.Create(this) ||
  98.         !m_wndStatusBar.SetIndicators(indicators,
  99.           sizeof(indicators)/sizeof(UINT)))
  100.     {
  101.         TRACE0("Failed to create status bar\n");
  102.         return -1;      // fail to create
  103.     }
  104.  
  105.     return 0;
  106. }
  107.  
  108. /////////////////////////////////////////////////////////////////////////////
  109. // CMainFrame diagnostics
  110.  
  111. #ifdef _DEBUG
  112. void CMainFrame::AssertValid() const
  113. {
  114.     CMDIFrameWnd::AssertValid();
  115. }
  116.  
  117. void CMainFrame::Dump(CDumpContext& dc) const
  118. {
  119.     CMDIFrameWnd::Dump(dc);
  120. }
  121.  
  122. #endif //_DEBUG
  123.  
  124. /////////////////////////////////////////////////////////////////////////////
  125. // CMainFrame message handlers
  126.  
  127. void CMainFrame::GetMessageString(UINT nID, CString& rMessage) const
  128. {
  129.     CString strMessage;
  130.     if (CDynaMenuDoc::GetMessageString(nID, rMessage))
  131.         return; // the document has provided the message string for the dynamic command i.d.
  132.  
  133.     CFrameWnd::GetMessageString(nID, rMessage);
  134. }
  135.