home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / mfc / advanced / dllhusk / mainfrm.cpp < prev    next >
C/C++ Source or Header  |  1998-03-26  |  3KB  |  135 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 "dllhusk.h"
  15.  
  16. #include "mainfrm.h"
  17.  
  18. #ifdef _DEBUG
  19. #undef THIS_FILE
  20. static char BASED_CODE THIS_FILE[] = __FILE__;
  21. #endif
  22.  
  23. /////////////////////////////////////////////////////////////////////////////
  24. // CMainFrame
  25.  
  26. IMPLEMENT_DYNAMIC(CMainFrame, CMDIFrameWnd)
  27.  
  28. BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd)
  29.     //{{AFX_MSG_MAP(CMainFrame)
  30.     ON_WM_CREATE()
  31.     ON_WM_NCRBUTTONDOWN()
  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_FILE_NEW,
  43.     ID_FILE_OPEN,
  44.     ID_FILE_SAVE,
  45.         ID_SEPARATOR,
  46.     ID_EDIT_CUT,
  47.     ID_EDIT_COPY,
  48.     ID_EDIT_PASTE,
  49.         ID_SEPARATOR,
  50.     ID_FILE_PRINT,
  51.     ID_APP_ABOUT,
  52. };
  53.  
  54. static UINT BASED_CODE indicators[] =
  55. {
  56.     ID_SEPARATOR,           // status line indicator
  57.     ID_INDICATOR_CAPS,
  58.     ID_INDICATOR_NUM,
  59.     ID_INDICATOR_SCRL,
  60. };
  61.  
  62. /////////////////////////////////////////////////////////////////////////////
  63. // CMainFrame construction/destruction
  64.  
  65. CMainFrame::CMainFrame()
  66. {
  67. }
  68.  
  69. CMainFrame::~CMainFrame()
  70. {
  71. }
  72.  
  73. int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
  74. {
  75.     if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1)
  76.         return -1;
  77.  
  78.     if (!m_wndToolBar.Create(this) ||
  79.         !m_wndToolBar.LoadBitmap(IDR_MAINFRAME) ||
  80.         !m_wndToolBar.SetButtons(buttons,
  81.           sizeof(buttons)/sizeof(UINT)))
  82.     {
  83.         TRACE0("Failed to create toolbar\n");
  84.         return -1;      // fail to create
  85.     }
  86.  
  87.     if (!m_wndStatusBar.Create(this) ||
  88.         !m_wndStatusBar.SetIndicators(indicators,
  89.           sizeof(indicators)/sizeof(UINT)))
  90.     {
  91.         TRACE0("Failed to create status bar\n");
  92.         return -1;      // fail to create
  93.     }
  94.  
  95.     return 0;
  96. }
  97.  
  98.  
  99. /////////////////////////////////////////////////////////////////////////////
  100. // CMainFrame diagnostics
  101.  
  102. #ifdef _DEBUG
  103. void CMainFrame::AssertValid() const
  104. {
  105.     CMDIFrameWnd::AssertValid();
  106. }
  107.  
  108. void CMainFrame::Dump(CDumpContext& dc) const
  109. {
  110.     CMDIFrameWnd::Dump(dc);
  111. }
  112.  
  113. #endif //_DEBUG
  114.  
  115. /////////////////////////////////////////////////////////////////////////////
  116. // CMainFrame commands
  117.  
  118. void CMainFrame::OnNcRButtonDown(UINT, CPoint point)
  119. {
  120.     &point; // not used in retail build
  121. #ifdef _DEBUG
  122.     // for debugging we support a right-mouse activated debug menu
  123.     CMenu menubar;
  124.     if (menubar.LoadMenu(IDR_POPUPMENUS))
  125.     {
  126.         // debug menu is the first popup
  127.         CMenu* pPopup = menubar.GetSubMenu(0);
  128.         ASSERT(pPopup != NULL);
  129.  
  130.         // route commands through this main frame
  131.         pPopup->TrackPopupMenu(TPM_RIGHTBUTTON, point.x, point.y, this);
  132.     }
  133. #endif
  134. }
  135.