home *** CD-ROM | disk | FTP | other *** search
/ Mastering Microsoft Visual C++ 4 (2nd Edition) / VisualC4.ISO / dlgdemo / dlgdedlg.cpp next >
Encoding:
C/C++ Source or Header  |  1995-11-30  |  4.4 KB  |  163 lines

  1. // DlgDeDlg.cpp : implementation file
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "DlgDemo.h"
  6. #include "DlgDeDlg.h"
  7.  
  8. #ifdef _DEBUG
  9. #define new DEBUG_NEW
  10. #undef THIS_FILE
  11. static char THIS_FILE[] = __FILE__;
  12. #endif
  13.  
  14. /////////////////////////////////////////////////////////////////////////////
  15. // CDlgDemoDlg dialog
  16.  
  17. CDlgDemoDlg::CDlgDemoDlg(CWnd* pParent /*=NULL*/)
  18.    : CDialog(CDlgDemoDlg::IDD, pParent)
  19. {
  20.    //{{AFX_DATA_INIT(CDlgDemoDlg)
  21.    m_Red = FALSE;
  22.    m_Green = FALSE;
  23.    m_Blue = FALSE;
  24.    m_Intensity = INT_LIGHT;
  25.    //}}AFX_DATA_INIT
  26.    // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
  27.    m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  28. }
  29.  
  30. void CDlgDemoDlg::DoDataExchange(CDataExchange* pDX)
  31. {
  32.    CDialog::DoDataExchange(pDX);
  33.    //{{AFX_DATA_MAP(CDlgDemoDlg)
  34.    DDX_Check(pDX, IDC_RED, m_Red);
  35.    DDX_Check(pDX, IDC_GREEN, m_Green);
  36.    DDX_Check(pDX, IDC_BLUE, m_Blue);
  37.    DDX_Radio(pDX, IDC_DARK, m_Intensity);
  38.    //}}AFX_DATA_MAP
  39. }
  40.  
  41. BEGIN_MESSAGE_MAP(CDlgDemoDlg, CDialog)
  42.    //{{AFX_MSG_MAP(CDlgDemoDlg)
  43.    ON_WM_PAINT()
  44.    ON_WM_QUERYDRAGICON()
  45.    ON_BN_CLICKED(IDC_RED, OnRed)
  46.    ON_BN_CLICKED(IDC_GREEN, OnGreen)
  47.    ON_BN_CLICKED(IDC_BLUE, OnBlue)
  48.    ON_BN_CLICKED(IDC_DARK, OnDark)
  49.    ON_BN_CLICKED(IDC_LIGHT, OnLight)
  50.    //}}AFX_MSG_MAP
  51. END_MESSAGE_MAP()
  52.  
  53. /////////////////////////////////////////////////////////////////////////////
  54. // CDlgDemoDlg message handlers
  55.  
  56. BOOL CDlgDemoDlg::OnInitDialog()
  57. {
  58.    CDialog::OnInitDialog();
  59.  
  60.    // Set the icon for this dialog.  The framework does this automatically
  61.    //  when the application's main window is not a dialog
  62.    SetIcon(m_hIcon, TRUE);       // Set big icon
  63.    SetIcon(m_hIcon, FALSE);      // Set small icon
  64.    
  65.    // TODO: Add extra initialization here
  66.  
  67.    GetDlgItem (IDC_SAMPLE)->GetWindowRect (&m_RectSample);   
  68.    ScreenToClient (&m_RectSample);
  69.    int Border = (m_RectSample.right - m_RectSample.left) / 8;
  70.    m_RectSample.InflateRect (-Border, -Border);
  71.  
  72.    return TRUE;  // return TRUE  unless you set the focus to a control
  73. }
  74.  
  75. // If you add a minimize button to your dialog, you will need the code below
  76. //  to draw the icon.  For MFC applications using the document/view model,
  77. //  this is automatically done for you by the framework.
  78.  
  79. void CDlgDemoDlg::OnPaint() 
  80. {
  81.    if (IsIconic())
  82.    {
  83.       CPaintDC dc(this); // device context for painting
  84.  
  85.       SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
  86.  
  87.       // Center icon in client rectangle
  88.       int cxIcon = GetSystemMetrics(SM_CXICON);
  89.       int cyIcon = GetSystemMetrics(SM_CYICON);
  90.       CRect rect;
  91.       GetClientRect(&rect);
  92.       int x = (rect.Width() - cxIcon + 1) / 2;
  93.       int y = (rect.Height() - cyIcon + 1) / 2;
  94.  
  95.       // Draw the icon
  96.       dc.DrawIcon(x, y, m_hIcon);
  97.    }
  98.    else
  99.    {
  100.       // deleted call to CDialog::OnPaint()
  101.       COLORREF Color = RGB
  102.          (m_Red ? (m_Intensity==INT_DARK ? 128 : 255) : 0,
  103.          m_Green ? (m_Intensity==INT_DARK ? 128 : 255) : 0,
  104.          m_Blue ? (m_Intensity==INT_DARK ? 128 : 255) : 0);
  105.       CBrush Brush (Color);
  106.       CPaintDC dc(this);
  107.       dc.FillRect (&m_RectSample, &Brush);
  108.    }
  109. }
  110.  
  111. // The system calls this to obtain the cursor to display while the user drags
  112. //  the minimized window.
  113. HCURSOR CDlgDemoDlg::OnQueryDragIcon()
  114. {
  115.    return (HCURSOR) m_hIcon;
  116. }
  117.  
  118. void CDlgDemoDlg::OnRed() 
  119. {
  120.    // TODO: Add your control notification handler code here
  121.    m_Red = IsDlgButtonChecked (IDC_RED);
  122.    InvalidateRect (&m_RectSample);
  123.    UpdateWindow ();
  124. }
  125.  
  126. void CDlgDemoDlg::OnGreen() 
  127. {
  128.    // TODO: Add your control notification handler code here
  129.    m_Green = IsDlgButtonChecked (IDC_GREEN);
  130.    InvalidateRect (&m_RectSample);
  131.    UpdateWindow ();
  132. }
  133.  
  134. void CDlgDemoDlg::OnBlue() 
  135. {
  136.    // TODO: Add your control notification handler code here
  137.    m_Blue = IsDlgButtonChecked (IDC_BLUE);
  138.    InvalidateRect (&m_RectSample);
  139.    UpdateWindow ();
  140. }
  141.  
  142. void CDlgDemoDlg::OnDark() 
  143. {
  144.    // TODO: Add your control notification handler code here
  145.    if (IsDlgButtonChecked (IDC_DARK))
  146.       {
  147.       m_Intensity = INT_DARK;
  148.       InvalidateRect (&m_RectSample);
  149.       UpdateWindow ();
  150.       }
  151. }
  152.  
  153. void CDlgDemoDlg::OnLight() 
  154. {
  155.    // TODO: Add your control notification handler code here
  156.    if (IsDlgButtonChecked (IDC_LIGHT))
  157.       {
  158.       m_Intensity = INT_LIGHT;
  159.       InvalidateRect (&m_RectSample);
  160.       UpdateWindow ();
  161.       }
  162. }
  163.