home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / mfc / advanced / mtrecalc / mainfrm.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-03-27  |  3.4 KB  |  140 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 "mtrecalc.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.     //}}AFX_MSG_MAP
  32.     ON_UPDATE_COMMAND_UI(ID_PERCENT_DONE, OnUpdatePercentDone)
  33.     ON_MESSAGE(WM_USER_RECALC_IN_PROGRESS, OnRecalcInProgress)
  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_FILE_NEW,
  44.     ID_FILE_OPEN,
  45.     ID_FILE_SAVE,
  46.         ID_SEPARATOR,
  47.     ID_EDIT_CUT,
  48.     ID_EDIT_COPY,
  49.     ID_EDIT_PASTE,
  50.         ID_SEPARATOR,
  51.     ID_FILE_PRINT,
  52.     ID_APP_ABOUT,
  53. };
  54.  
  55. static UINT BASED_CODE indicators[] =
  56. {
  57.     ID_SEPARATOR,           // status line indicator
  58.     ID_PERCENT_DONE,
  59.     ID_INDICATOR_CAPS,
  60.     ID_INDICATOR_NUM,
  61.     ID_INDICATOR_SCRL,
  62. };
  63.  
  64. /////////////////////////////////////////////////////////////////////////////
  65. // CMainFrame construction/destruction
  66.  
  67. CMainFrame::CMainFrame()
  68. {
  69.     m_nPercentDone = 100;
  70. }
  71.  
  72. CMainFrame::~CMainFrame()
  73. {
  74. }
  75.  
  76. int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
  77. {
  78.     if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1)
  79.         return -1;
  80.  
  81.     if (!m_wndToolBar.Create(this) ||
  82.         !m_wndToolBar.LoadBitmap(IDR_MAINFRAME) ||
  83.         !m_wndToolBar.SetButtons(buttons,
  84.           sizeof(buttons)/sizeof(UINT)))
  85.     {
  86.         TRACE0("Failed to create toolbar\n");
  87.         return -1;      // fail to create
  88.     }
  89.  
  90.     if (!m_wndStatusBar.Create(this) ||
  91.         !m_wndStatusBar.SetIndicators(indicators,
  92.           sizeof(indicators)/sizeof(UINT)))
  93.     {
  94.         TRACE0("Failed to create status bar\n");
  95.         return -1;      // fail to create
  96.     }
  97.  
  98.     m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
  99.     EnableDocking(CBRS_ALIGN_ANY);
  100.     DockControlBar(&m_wndToolBar);
  101.  
  102.     return 0;
  103. }
  104.  
  105. /////////////////////////////////////////////////////////////////////////////
  106. // CMainFrame diagnostics
  107.  
  108. #ifdef _DEBUG
  109. void CMainFrame::AssertValid() const
  110. {
  111.     CMDIFrameWnd::AssertValid();
  112. }
  113.  
  114. void CMainFrame::Dump(CDumpContext& dc) const
  115. {
  116.     CMDIFrameWnd::Dump(dc);
  117. }
  118.  
  119. #endif //_DEBUG
  120.  
  121. /////////////////////////////////////////////////////////////////////////////
  122. // CMainFrame message handlers
  123.  
  124. void CMainFrame::OnUpdatePercentDone(CCmdUI* pCmdUI)
  125. {
  126.     // It is necessary to enable the percent-done status bar pane, so that
  127.     // the text will be displayed.
  128.     pCmdUI->Enable();
  129. }
  130.  
  131. LRESULT CMainFrame::OnRecalcInProgress(WPARAM wParam, LPARAM)
  132. {
  133.     m_nPercentDone = wParam;
  134.     CString strPercentDone;
  135.     strPercentDone.Format("%i%c", m_nPercentDone, '%');
  136.     m_wndStatusBar.SetPaneText(m_wndStatusBar.CommandToIndex(ID_PERCENT_DONE), strPercentDone);
  137.     m_wndStatusBar.UpdateWindow();
  138.     return 0;
  139. }
  140.