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

  1. // MainFrm.cpp : implementation of the CMainFrame class
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "CustSBar.h"
  6.  
  7. #include "MyStatBa.h"
  8.  
  9. #include "MainFrm.h"
  10.  
  11. #ifdef _DEBUG
  12. #define new DEBUG_NEW
  13. #undef THIS_FILE
  14. static char THIS_FILE[] = __FILE__;
  15. #endif
  16.  
  17. /////////////////////////////////////////////////////////////////////////////
  18. // CMainFrame
  19.  
  20. IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)
  21.  
  22. BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
  23.     //{{AFX_MSG_MAP(CMainFrame)
  24.     ON_WM_CREATE()
  25.     ON_WM_SIZE()
  26.     //}}AFX_MSG_MAP
  27. END_MESSAGE_MAP()
  28.  
  29. /////////////////////////////////////////////////////////////////////////////
  30. // CMainFrame construction/destruction
  31.  
  32. CMainFrame::CMainFrame()
  33. {
  34. }
  35.  
  36. CMainFrame::~CMainFrame()
  37. {
  38. }
  39.  
  40. int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
  41. {
  42.     if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
  43.         return -1;
  44.     
  45.     if (!m_wndToolBar.Create(this) ||
  46.         !m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
  47.     {
  48.         TRACE0("Failed to create toolbar\n");
  49.         return -1;      // fail to create
  50.     }
  51.     
  52.     if (FALSE == BuildStatusBar())
  53.     {
  54.         TRACE0("Failed to create status bar\n");
  55.         return -1;      // fail to create
  56.     }
  57.  
  58.     // TODO: Remove this if you don't want tool tips or a resizeable toolbar
  59.     m_wndToolBar.SetBarStyle(m_wndToolBar.GetBarStyle() |
  60.         CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC);
  61.  
  62.     // TODO: Delete these three lines if you don't want the toolbar to
  63.     //  be dockable
  64.     m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
  65.     EnableDocking(CBRS_ALIGN_ANY);
  66.     DockControlBar(&m_wndToolBar);
  67.  
  68.     return 0;
  69. }
  70.  
  71. BOOL CMainFrame::BuildStatusBar()
  72. {
  73.     CRect rcSB(0, 0, 0, 0);
  74.  
  75.     if (!m_wndStatusBar.Create(
  76.         WS_VISIBLE | WS_CHILD | CCS_BOTTOM | SBARS_SIZEGRIP, 
  77.         rcSB, this, AFX_IDW_STATUS_BAR))
  78.     {
  79.         TRACE0("Failed to create status bar\n");
  80.         return FALSE;
  81.     }
  82.  
  83.     // The actual work of determining the number of panes,
  84.     // their types and contents is performed in the status
  85.     // bar's own OnSize function. However, it's necessary
  86.     // here to initialize the structure that is passed to
  87.     // pane 3, which is an owner draw pane. See comments in
  88.     // the status bar's DrawItem function, and the view
  89.     // class's command handler which sets the text color.
  90.     pt.bitmapID = IDM_BLACKBITMAP;
  91.  
  92.     return TRUE;
  93. }
  94.  
  95. BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
  96. {
  97.     return CFrameWnd::PreCreateWindow(cs);
  98. }
  99.  
  100. /////////////////////////////////////////////////////////////////////////////
  101. // CMainFrame message handlers
  102. void CMainFrame::OnSize(UINT nType, int cx, int cy) 
  103. {
  104.     CFrameWnd::OnSize(nType, cx, cy);
  105.     
  106.     // Force the status bar to move also, but only if its Create
  107.     // function has been called, which instantiates its m_hWnd.
  108.     if (m_wndStatusBar.m_hWnd)
  109.         m_wndStatusBar.MoveWindow(0, cy, cx, cy, TRUE);    
  110. }
  111.  
  112. BOOL CMainFrame::OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo) 
  113. {
  114.     // This turns out to be, perhaps, the easiest way to integrate
  115.     // the custom status bar into the application's command
  116.     // routing scheme.
  117.     m_wndStatusBar.DetermineKeyboardState();
  118.     m_wndStatusBar.DetermineTextColor();
  119.         
  120.     return CFrameWnd::OnCmdMsg(nID, nCode, pExtra, pHandlerInfo);
  121. }
  122.  
  123. /////////////////////////////////////////////////////////////////////////////
  124. // CMainFrame diagnostics
  125.  
  126. #ifdef _DEBUG
  127. void CMainFrame::AssertValid() const
  128. {
  129.     CFrameWnd::AssertValid();
  130. }
  131.  
  132. void CMainFrame::Dump(CDumpContext& dc) const
  133. {
  134.     CFrameWnd::Dump(dc);
  135. }
  136.  
  137. #endif //_DEBUG
  138.