home *** CD-ROM | disk | FTP | other *** search
/ Master Visual C++ 1.5 / MASTERVC15.ISO / vcprog / original / ch10 / mycombo / mydlg.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1994-01-18  |  2.7 KB  |  123 lines

  1. // mydlg.cpp : implementation file
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "mycombo.h"
  6. #include "mydlg.h"
  7.  
  8. #ifdef _DEBUG
  9. #undef THIS_FILE
  10. static char BASED_CODE THIS_FILE[] = __FILE__;
  11. #endif
  12.  
  13. /////////////////////////////////////////////////////////////////////////////
  14. // CMyDlg dialog
  15.  
  16.  
  17. CMyDlg::CMyDlg(CWnd* pParent /*=NULL*/)
  18.     : CDialog(CMyDlg::IDD, pParent)
  19. {
  20.     //{{AFX_DATA_INIT(CMyDlg)
  21.     m_SelectedItem = "";
  22.     //}}AFX_DATA_INIT
  23.  
  24.      //////////////////////
  25.      // MY CODE STARTS HERE
  26.      //////////////////////
  27.  
  28.      m_CurrentSelectedItem = 3;
  29.  
  30.      m_Item[0] = "Item 0";
  31.      m_Item[1] = "Item 1";
  32.      m_Item[2] = "Item 2";
  33.      m_Item[3] = "Item 3";
  34.      m_Item[4] = "Item 4";
  35.      m_Item[5] = "Item 5";
  36.  
  37.      ////////////////////
  38.      // MY CODE ENDS HERE
  39.      ////////////////////
  40.  
  41. }
  42.  
  43. void CMyDlg::DoDataExchange(CDataExchange* pDX)
  44. {
  45.     CDialog::DoDataExchange(pDX);
  46.     //{{AFX_DATA_MAP(CMyDlg)
  47.     DDX_CBString(pDX, IDC_COMBO1, m_SelectedItem);
  48.     //}}AFX_DATA_MAP
  49. }
  50.  
  51. BEGIN_MESSAGE_MAP(CMyDlg, CDialog)
  52.     //{{AFX_MSG_MAP(CMyDlg)
  53.     //}}AFX_MSG_MAP
  54. END_MESSAGE_MAP()
  55.  
  56.  
  57. /////////////////////////////////////////////////////////////////////////////
  58. // CMyDlg message handlers
  59.  
  60. BOOL CMyDlg::OnInitDialog()
  61. {
  62.     CDialog::OnInitDialog();
  63.     
  64.     // TODO: Add extra initialization here
  65.  
  66.      //////////////////////
  67.      // MY CODE STARTS HERE
  68.      //////////////////////
  69.  
  70.     // Fill the items of the list.
  71.     for (int i=0; i<=5; i++ )
  72.         {
  73.          SendDlgItemMessage(IDC_COMBO1,
  74.                            CB_ADDSTRING,
  75.                            0,
  76.                 (LPARAM)(LPSTR)(const char *)m_Item[i]);
  77.         }
  78.  
  79.     // Set the selected item to the third item.
  80.     SendDlgItemMessage(IDC_COMBO1,
  81.                        CB_SETCURSEL,
  82.                        m_CurrentSelectedItem,
  83.                        0);
  84.  
  85.     ////////////////////
  86.     // MY CODE ENDS HERE
  87.     ////////////////////
  88.  
  89.     
  90.     return TRUE;  // return TRUE  unless you set the focus to a control
  91. }
  92.  
  93. void CMyDlg::OnOK()
  94. {
  95.     // TODO: Add extra validation here
  96.  
  97.  
  98.      //////////////////////
  99.      // MY CODE STARTS HERE
  100.      //////////////////////
  101.  
  102.      m_CurrentSelectedItem =
  103.               (int) SendDlgItemMessage(IDC_COMBO1,
  104.                                        CB_GETCURSEL,
  105.                                        0,
  106.                                        0);
  107.  
  108.      if ( m_CurrentSelectedItem == CB_ERR )
  109.         {
  110.         MessageBox ( "Nothing is selected in the list. Forcing Item 3" );
  111.  
  112.         // Set the selected item to the third item.
  113.         m_CurrentSelectedItem = 3;
  114.  
  115.         }
  116.  
  117.      ////////////////////
  118.      // MY CODE ENDS HERE
  119.      ////////////////////
  120.     
  121.     CDialog::OnOK();
  122. }
  123.