home *** CD-ROM | disk | FTP | other *** search
/ Mastering Microsoft Visual C++ 4 (2nd Edition) / VisualC4.ISO / formdemo / formdevw.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1995-11-30  |  4.9 KB  |  193 lines

  1. // FormDeVw.cpp : implementation of the CFormDemoView class
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "FormDemo.h"
  6.  
  7. #include "FormDDoc.h"
  8. #include "FormDeVw.h"
  9.  
  10. #ifdef _DEBUG
  11. #define new DEBUG_NEW
  12. #undef THIS_FILE
  13. static char THIS_FILE[] = __FILE__;
  14. #endif
  15.  
  16. /////////////////////////////////////////////////////////////////////////////
  17. // CFormDemoView
  18.  
  19. IMPLEMENT_DYNCREATE(CFormDemoView, CFormView)
  20.  
  21. BEGIN_MESSAGE_MAP(CFormDemoView, CFormView)
  22.    //{{AFX_MSG_MAP(CFormDemoView)
  23.    ON_COMMAND(ID_OPTIONS_DARK, OnOptionsDark)
  24.    ON_UPDATE_COMMAND_UI(ID_OPTIONS_DARK, OnUpdateOptionsDark)
  25.    ON_COMMAND(ID_OPTIONS_LIGHT, OnOptionsLight)
  26.    ON_UPDATE_COMMAND_UI(ID_OPTIONS_LIGHT, OnUpdateOptionsLight)
  27.    ON_BN_CLICKED(IDC_RED, OnRed)
  28.    ON_BN_CLICKED(IDC_GREEN, OnGreen)
  29.    ON_BN_CLICKED(IDC_BLUE, OnBlue)
  30.    //}}AFX_MSG_MAP
  31. END_MESSAGE_MAP()
  32.  
  33. /////////////////////////////////////////////////////////////////////////////
  34. // CFormDemoView construction/destruction
  35.  
  36. CFormDemoView::CFormDemoView()
  37.    : CFormView(CFormDemoView::IDD)
  38. {
  39.    //{{AFX_DATA_INIT(CFormDemoView)
  40.    m_Red = FALSE;
  41.    m_Green = FALSE;
  42.    m_Blue = FALSE;
  43.    //}}AFX_DATA_INIT
  44.    // TODO: add construction code here
  45.  
  46.    m_Intensity =  INT_LIGHT;
  47. }
  48.  
  49. CFormDemoView::~CFormDemoView()
  50. {
  51. }
  52.  
  53. void CFormDemoView::DoDataExchange(CDataExchange* pDX)
  54. {
  55.    CFormView::DoDataExchange(pDX);
  56.    //{{AFX_DATA_MAP(CFormDemoView)
  57.    DDX_Check(pDX, IDC_RED, m_Red);
  58.    DDX_Check(pDX, IDC_GREEN, m_Green);
  59.    DDX_Check(pDX, IDC_BLUE, m_Blue);
  60.    //}}AFX_DATA_MAP
  61. }
  62.  
  63. BOOL CFormDemoView::PreCreateWindow(CREATESTRUCT& cs)
  64. {
  65.    // TODO: Modify the Window class or styles here by modifying
  66.    //  the CREATESTRUCT cs
  67.  
  68.    return CFormView::PreCreateWindow(cs);
  69. }
  70.  
  71. /////////////////////////////////////////////////////////////////////////////
  72. // CFormDemoView diagnostics
  73.  
  74. #ifdef _DEBUG
  75. void CFormDemoView::AssertValid() const
  76. {
  77.    CFormView::AssertValid();
  78. }
  79.  
  80. void CFormDemoView::Dump(CDumpContext& dc) const
  81. {
  82.    CFormView::Dump(dc);
  83. }
  84.  
  85. CFormDemoDoc* CFormDemoView::GetDocument() // non-debug version is inline
  86. {
  87.    ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CFormDemoDoc)));
  88.    return (CFormDemoDoc*)m_pDocument;
  89. }
  90. #endif //_DEBUG
  91.  
  92. /////////////////////////////////////////////////////////////////////////////
  93. // CFormDemoView message handlers
  94.  
  95. void CFormDemoView::OnOptionsDark() 
  96. {
  97.    // TODO: Add your command handler code here
  98.    m_Intensity = INT_DARK;
  99.  
  100.    CClientDC ClientDC (this);
  101.    OnPrepareDC (&ClientDC);
  102.    CRect Rect = m_RectSample;
  103.    ClientDC.LPtoDP (&Rect);
  104.    InvalidateRect (&Rect);
  105.    UpdateWindow ();
  106. }
  107.  
  108. void CFormDemoView::OnUpdateOptionsDark(CCmdUI* pCmdUI) 
  109. {
  110.    // TODO: Add your command update UI handler code here
  111.    pCmdUI->SetRadio (m_Intensity == INT_DARK);  
  112. }
  113.  
  114. void CFormDemoView::OnOptionsLight() 
  115. {
  116.    // TODO: Add your command handler code here
  117.    m_Intensity = INT_LIGHT;
  118.  
  119.    CClientDC ClientDC (this);
  120.    OnPrepareDC (&ClientDC);
  121.    CRect Rect = m_RectSample;
  122.    ClientDC.LPtoDP (&Rect);
  123.    InvalidateRect (&Rect);
  124.    UpdateWindow ();
  125. }
  126.  
  127. void CFormDemoView::OnUpdateOptionsLight(CCmdUI* pCmdUI) 
  128. {
  129.    // TODO: Add your command update UI handler code here
  130.    pCmdUI->SetRadio (m_Intensity == INT_LIGHT); 
  131. }
  132.  
  133. void CFormDemoView::OnRed() 
  134. {
  135.    // TODO: Add your control notification handler code here
  136.    m_Red = IsDlgButtonChecked (IDC_RED);
  137.  
  138.    CClientDC ClientDC (this);
  139.    OnPrepareDC (&ClientDC);
  140.    CRect Rect = m_RectSample;
  141.    ClientDC.LPtoDP (&Rect);
  142.    InvalidateRect (&Rect);
  143.    UpdateWindow ();
  144. }
  145.  
  146. void CFormDemoView::OnGreen() 
  147. {
  148.    // TODO: Add your control notification handler code here
  149.    m_Green = IsDlgButtonChecked (IDC_GREEN);
  150.  
  151.    CClientDC ClientDC (this);
  152.    OnPrepareDC (&ClientDC);
  153.    CRect Rect = m_RectSample;
  154.    ClientDC.LPtoDP (&Rect);
  155.    InvalidateRect (&Rect);
  156.    UpdateWindow ();
  157. }
  158.  
  159. void CFormDemoView::OnBlue() 
  160. {
  161.    // TODO: Add your control notification handler code here
  162.    m_Blue = IsDlgButtonChecked (IDC_BLUE);
  163.  
  164.    CClientDC ClientDC (this);
  165.    OnPrepareDC (&ClientDC);
  166.    CRect Rect = m_RectSample;
  167.    ClientDC.LPtoDP (&Rect);
  168.    InvalidateRect (&Rect);
  169.    UpdateWindow ();
  170. }
  171.  
  172. void CFormDemoView::OnDraw(CDC* pDC) 
  173. {
  174.    // TODO: Add your specialized code here and/or call the base class
  175.    COLORREF Color = RGB
  176.       (m_Red ? (m_Intensity==INT_DARK ? 128 : 255) : 0,
  177.       m_Green ? (m_Intensity==INT_DARK ? 128 : 255) : 0,
  178.       m_Blue ? (m_Intensity==INT_DARK ? 128 : 255) : 0);
  179.    CBrush Brush (Color);
  180.    pDC->FillRect (&m_RectSample, &Brush);
  181. }
  182.  
  183. void CFormDemoView::OnInitialUpdate() 
  184. {
  185.    CFormView::OnInitialUpdate();
  186.    
  187.    // TODO: Add your specialized code here and/or call the base class
  188.    GetDlgItem (IDC_SAMPLE)->GetWindowRect (&m_RectSample);   
  189.    ScreenToClient (&m_RectSample);
  190.    int Border = (m_RectSample.right - m_RectSample.left) / 8;
  191.    m_RectSample.InflateRect (-Border, -Border);
  192. }
  193.