home *** CD-ROM | disk | FTP | other *** search
/ Mastering MFC Development / MMD.ISO / labs / c05 / lab05 / ex02 / mainfrm.cpp next >
Encoding:
C/C++ Source or Header  |  1997-02-20  |  2.8 KB  |  125 lines

  1. // MainFrm.cpp : implementation of the CMainFrame class
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "TimeStamp.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_DYNCREATE(CMainFrame, CFrameWnd)
  19.  
  20. BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
  21.     //{{AFX_MSG_MAP(CMainFrame)
  22.     ON_WM_CREATE()
  23.     ON_WM_TIMER()
  24.     //}}AFX_MSG_MAP
  25.     ON_UPDATE_COMMAND_UI(ID_INDICATOR_TIME, OnUpdateTime)
  26. END_MESSAGE_MAP()
  27.  
  28. static UINT indicators[] =
  29. {
  30.     ID_SEPARATOR,           // status line indicator
  31.     ID_INDICATOR_CAPS,
  32.     ID_INDICATOR_NUM,
  33.     ID_INDICATOR_SCRL,
  34.     ID_INDICATOR_TIME
  35. };
  36.  
  37. /////////////////////////////////////////////////////////////////////////////
  38. // CMainFrame construction/destruction
  39.  
  40. CMainFrame::CMainFrame()
  41. {
  42.     // TODO: add member initialization code here
  43.     
  44. }
  45.  
  46. CMainFrame::~CMainFrame()
  47. {
  48. }
  49.  
  50. int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
  51. {
  52.     if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
  53.         return -1;
  54.     
  55.     if (!m_wndToolBar.Create(this) ||
  56.         !m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
  57.     {
  58.         TRACE0("Failed to create toolbar\n");
  59.         return -1;      // fail to create
  60.     }
  61.  
  62.     if (!m_wndStatusBar.Create(this) ||
  63.         !m_wndStatusBar.SetIndicators(indicators,
  64.           sizeof(indicators)/sizeof(UINT)))
  65.     {
  66.         TRACE0("Failed to create status bar\n");
  67.         return -1;      // fail to create
  68.     }
  69.  
  70.     // TODO: Remove this if you don't want tool tips or a resizeable toolbar
  71.     m_wndToolBar.SetBarStyle(m_wndToolBar.GetBarStyle() |
  72.         CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC);
  73.  
  74.     // TODO: Delete these three lines if you don't want the toolbar to
  75.     //  be dockable
  76.     m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
  77.     EnableDocking(CBRS_ALIGN_ANY);
  78.     DockControlBar(&m_wndToolBar);
  79.  
  80.     SetTimer(1234, 1000, NULL);
  81.  
  82.     return 0;
  83. }
  84.  
  85. BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
  86. {
  87.     // TODO: Modify the Window class or styles here by modifying
  88.     //  the CREATESTRUCT cs
  89.  
  90.     return CFrameWnd::PreCreateWindow(cs);
  91. }
  92.  
  93. /////////////////////////////////////////////////////////////////////////////
  94. // CMainFrame diagnostics
  95.  
  96. #ifdef _DEBUG
  97. void CMainFrame::AssertValid() const
  98. {
  99.     CFrameWnd::AssertValid();
  100. }
  101.  
  102. void CMainFrame::Dump(CDumpContext& dc) const
  103. {
  104.     CFrameWnd::Dump(dc);
  105. }
  106.  
  107. #endif //_DEBUG
  108.  
  109. /////////////////////////////////////////////////////////////////////////////
  110. // CMainFrame message handlers
  111.  
  112. void CMainFrame::OnUpdateTime(CCmdUI * pCmdUI)
  113. {
  114.     CTime time = CTime::GetCurrentTime();
  115.     CString sTime = time.Format("%I:%M %p");
  116.     pCmdUI->SetText(sTime);
  117. }
  118.  
  119. void CMainFrame::OnTimer(UINT nIDEvent) 
  120. {
  121.     // TODO: Add your message handler code here and/or call default
  122.     
  123.     CFrameWnd::OnTimer(nIDEvent);
  124. }
  125.