home *** CD-ROM | disk | FTP | other *** search
/ Mastering MFC Development / MMD.ISO / samples / c07 / mdi2viewsb / childfrm.cpp next >
Encoding:
C/C++ Source or Header  |  1997-02-20  |  2.2 KB  |  98 lines

  1. // ChildFrm.cpp : implementation of the CChildFrame class
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "MDI2ViewsB.h"
  6.  
  7. #include "mdi2viewsBdoc.h"
  8. #include "ChildFrm.h"
  9.  
  10. #ifdef _DEBUG
  11. #define new DEBUG_NEW
  12. #undef THIS_FILE
  13. static char THIS_FILE[] = __FILE__;
  14. #endif
  15.  
  16. const COLORREF BLACK=RGB(0,0,0);
  17. const COLORREF RED=RGB(255,0,0);
  18. const COLORREF GREEN=RGB(0,255,0);
  19. const COLORREF BLUE=RGB(0,0,255);
  20.  
  21. /////////////////////////////////////////////////////////////////////////////
  22. // CChildFrame
  23.  
  24. IMPLEMENT_DYNCREATE(CChildFrame, CMDIChildWnd)
  25.  
  26. BEGIN_MESSAGE_MAP(CChildFrame, CMDIChildWnd)
  27.     //{{AFX_MSG_MAP(CChildFrame)
  28.     //}}AFX_MSG_MAP
  29.     ON_COMMAND_RANGE(ID_COLORS_BLACK, ID_COLORS_BLUE, OnColors)
  30.     ON_UPDATE_COMMAND_UI_RANGE(ID_COLORS_BLACK, ID_COLORS_BLUE, OnUpdateColors)
  31. END_MESSAGE_MAP()
  32.  
  33. /////////////////////////////////////////////////////////////////////////////
  34. // CChildFrame construction/destruction
  35.  
  36. CChildFrame::CChildFrame()
  37. {
  38. }
  39.  
  40. CChildFrame::~CChildFrame()
  41. {
  42. }
  43.  
  44. BOOL CChildFrame::PreCreateWindow(CREATESTRUCT& cs)
  45. {
  46.     return CMDIChildWnd::PreCreateWindow(cs);
  47. }
  48.  
  49. /////////////////////////////////////////////////////////////////////////////
  50. // CChildFrame diagnostics
  51.  
  52. #ifdef _DEBUG
  53. void CChildFrame::AssertValid() const
  54. {
  55.     CMDIChildWnd::AssertValid();
  56. }
  57.  
  58. void CChildFrame::Dump(CDumpContext& dc) const
  59. {
  60.     CMDIChildWnd::Dump(dc);
  61. }
  62. #endif //_DEBUG
  63.  
  64. /////////////////////////////////////////////////////////////////////////////
  65. // CChildFrame message handlers
  66. void CChildFrame::OnColors(UINT nID) 
  67. {
  68.     CMDI2ViewsBDoc* pDoc;
  69.     pDoc = (CMDI2ViewsBDoc*)GetActiveDocument();
  70.  
  71.     pDoc->SetColor(IDtoColorRef(nID));
  72.     pDoc->UpdateAllViews(NULL);
  73. }
  74.  
  75. void CChildFrame::OnUpdateColors(CCmdUI* pCmdUI)
  76. {
  77.     CMDI2ViewsBDoc* pDoc;
  78.     pDoc = (CMDI2ViewsBDoc*)GetActiveDocument();
  79.  
  80.     pCmdUI->SetCheck(pDoc->GetColor() == IDtoColorRef(pCmdUI->m_nID));
  81. }
  82.  
  83. // This function converts one of the 4 Command IDs to a COLORREF value.
  84. COLORREF CChildFrame::IDtoColorRef(int nID)
  85. {
  86.     switch (nID)
  87.     {
  88.         case ID_COLORS_RED:
  89.             return RED;
  90.         case ID_COLORS_GREEN:
  91.             return GREEN;        
  92.         case ID_COLORS_BLUE:
  93.             return BLUE;
  94.         default:
  95.             return BLACK;        
  96.     }
  97. }
  98.