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

  1. // MainFrm.cpp : implementation of the CMainFrame class
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "StatBar.h"
  6.  
  7. #include "MainFrm.h"
  8.  
  9. #include "StatBDoc.h"
  10.  
  11. #ifdef _DEBUG
  12. #define new DEBUG_NEW
  13. #undef THIS_FILE
  14. static char THIS_FILE[] = __FILE__;
  15. #endif
  16.  
  17. const COLORREF WHITE=RGB(255,255,255);
  18. const COLORREF BLACK=RGB(0,0,0);
  19. const COLORREF RED=RGB(255,0,0);
  20. const COLORREF GREEN=RGB(0,255,0);
  21. const COLORREF BLUE=RGB(0,0,255);
  22.  
  23. /////////////////////////////////////////////////////////////////////////////
  24. // CMainFrame
  25.  
  26. IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)
  27.  
  28. BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
  29.     //{{AFX_MSG_MAP(CMainFrame)
  30.     ON_WM_CREATE()
  31.     ON_UPDATE_COMMAND_UI(ID_COLORS_COLORS, OnUpdateColorsColors)
  32.     //}}AFX_MSG_MAP
  33. END_MESSAGE_MAP()
  34.  
  35. static UINT indicators[] =
  36. {
  37.     ID_SEPARATOR,           // status line indicator
  38.     ID_INDICATOR_CAPS,
  39.     ID_INDICATOR_NUM,
  40.     ID_INDICATOR_SCRL,
  41.     ID_COLORS_COLORS,       // width is established by the length
  42.                             // of the Prompt string in the menu item
  43.                             // which establishes a command, and hence
  44.                             // command handler.
  45. };
  46.  
  47. /////////////////////////////////////////////////////////////////////////////
  48. // CMainFrame construction/destruction
  49.  
  50. CMainFrame::CMainFrame()
  51. {
  52. }
  53.  
  54. CMainFrame::~CMainFrame()
  55. {
  56. }
  57.  
  58. int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
  59. {
  60.     if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
  61.         return -1;
  62.  
  63.     if (!m_wndStatusBar.Create(this) ||
  64.         !m_wndStatusBar.SetIndicators(indicators,
  65.           sizeof(indicators)/sizeof(UINT)))
  66.     {
  67.         TRACE0("Failed to create status bar\n");
  68.         return -1;      // fail to create
  69.     }
  70.  
  71.     return 0;
  72. }
  73.  
  74. BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
  75. {
  76.     return CFrameWnd::PreCreateWindow(cs);
  77. }
  78.  
  79. /////////////////////////////////////////////////////////////////////////////
  80. // CMainFrame diagnostics
  81.  
  82. #ifdef _DEBUG
  83. void CMainFrame::AssertValid() const
  84. {
  85.     CFrameWnd::AssertValid();
  86. }
  87.  
  88. void CMainFrame::Dump(CDumpContext& dc) const
  89. {
  90.     CFrameWnd::Dump(dc);
  91. }
  92.  
  93. #endif //_DEBUG
  94.  
  95. /////////////////////////////////////////////////////////////////////////////
  96. // CMainFrame message handlers
  97. void CMainFrame::OnUpdateColorsColors(CCmdUI* pCmdUI) 
  98. {
  99.     CStatusBarsDoc* pDoc = (CStatusBarsDoc*)GetActiveDocument();
  100.     CString color;
  101.  
  102.     switch (pDoc->GetColor())
  103.     {
  104.         case BLACK:
  105.             color = "Black";        
  106.             break;
  107.         case RED:
  108.             color = "Red";        
  109.             break;
  110.         case GREEN:
  111.             color = "Green";        
  112.             break;
  113.         case BLUE:
  114.             color = "Blue";        
  115.     }
  116.  
  117.     pCmdUI->SetText(color);
  118. }
  119.