home *** CD-ROM | disk | FTP | other *** search
/ Mastering MFC Development / MMD.ISO / samples / c06 / tabbed / colortab.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1997-02-20  |  3.0 KB  |  110 lines

  1. // ColorTab.cpp : implementation file
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "tabbed.h"
  6. #include "ClrLstBx.h"
  7. #include "ColorTab.h"
  8. #include "XtraFunc.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. // CColorTab property page
  18.  
  19. IMPLEMENT_DYNCREATE(CColorTab, CPropertyPage)
  20.  
  21. CColorTab::CColorTab() : CPropertyPage(CColorTab::IDD)
  22. {
  23.     //{{AFX_DATA_INIT(CColorTab)
  24.     m_colorRadio = -1;
  25.     m_colorList = -1;
  26.     //}}AFX_DATA_INIT
  27. }
  28.  
  29. CColorTab::~CColorTab()
  30. {
  31. }
  32.  
  33. void CColorTab::DoDataExchange(CDataExchange* pDX)
  34. {
  35.     CPropertyPage::DoDataExchange(pDX);
  36.  
  37.     //{{AFX_DATA_MAP(CColorTab)
  38.     DDX_Radio(pDX, IDC_BLACK, m_colorRadio);
  39.     DDX_LBIndex(pDX, IDC_COLOR_LIST, m_colorList);
  40.     //}}AFX_DATA_MAP
  41.  
  42.     // If you want the list box's ItemData field available
  43.     // in the dialog class, you've got to do the transfer
  44.     // yourself. For this particular variable (m_color)
  45.     // true DDX isn't appropriate. The variable m_color
  46.     // is used to set the initial list box selection in
  47.     // OnInitDialog.
  48.  
  49.     if (pDX->m_bSaveAndValidate)
  50.     {
  51.         int cs = m_colorListBox.GetCurSel();
  52.         m_color = m_colorListBox.GetItemData(cs);
  53.     }
  54. }
  55.  
  56. BEGIN_MESSAGE_MAP(CColorTab, CPropertyPage)
  57.     //{{AFX_MSG_MAP(CColorTab)
  58.     ON_LBN_SELCHANGE(IDC_COLOR_LIST, OnSelchangeColorList)
  59.     //}}AFX_MSG_MAP
  60.     ON_CONTROL_RANGE(BN_CLICKED, IDC_BLACK, IDC_BLUE, OnRadioClicked )
  61. END_MESSAGE_MAP()
  62.  
  63. /////////////////////////////////////////////////////////////////////////////
  64. // CColorTab message handlers
  65.  
  66. BOOL CColorTab::OnInitDialog() 
  67. {
  68.     CPropertyPage::OnInitDialog();
  69.  
  70.     // Subclass the control. From now on all references to the
  71.     // control on the dialog box will be via the custom
  72.     // list box m_colorListBox.
  73.     m_colorListBox.SubclassDlgItem(IDC_COLOR_LIST, this);
  74.     
  75.     // Add 4 colors to the listbox. See DrawItem in the
  76.     // derived list box's implementation file to see how
  77.     // this value is used.
  78.     m_colorListBox.AddString((LPCTSTR) BLACK);
  79.     m_colorListBox.AddString((LPCTSTR) RED);
  80.     m_colorListBox.AddString((LPCTSTR) GREEN);
  81.     m_colorListBox.AddString((LPCTSTR) BLUE);
  82.  
  83.     // Set the initial selection in the radio buttons
  84.     // and the list box.
  85.     m_colorList = m_colorRadio = RgbToInt(m_color);
  86.     
  87.     return TRUE;
  88. }
  89.  
  90. // In order to make the list box and the group of radio
  91. // buttons operate in sync, when the selection changes in
  92. // the list box, change the radio button as well.
  93. void CColorTab::OnSelchangeColorList() 
  94. {
  95.     m_colorList = m_colorRadio = m_colorListBox.GetCurSel();
  96.     UpdateData(FALSE);
  97. }
  98.  
  99. // Click events for all four radio buttons end up here.
  100. // See this class's message map for more information.
  101. // When the radio button changes, change selection in
  102. // the list box also. Since the radio buttons have
  103. // consecutive IDs, a simple subtraction provides the 
  104. // needed integer.
  105. void CColorTab::OnRadioClicked(UINT nID) 
  106. {
  107.     m_colorList = m_colorRadio = nID - IDC_BLACK;
  108.     UpdateData(FALSE);
  109. }
  110.