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

  1. // mydlg.cpp : implementation file
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "mylist.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.  
  21.      //////////////////////
  22.      // MY CODE STARTS HERE
  23.      //////////////////////
  24.  
  25.      m_CurrentSelectedItem = 3;
  26.  
  27.      m_TotalItems = 6;
  28.  
  29.      m_Item[0] = "Item 0";
  30.      m_Item[1] = "Item 1";
  31.      m_Item[2] = "Item 2";
  32.      m_Item[3] = "Item 3";
  33.      m_Item[4] = "Item 4";
  34.      m_Item[5] = "Item 5";
  35.  
  36.      ////////////////////
  37.      // MY CODE ENDS HERE
  38.      ////////////////////
  39.  
  40.     //{{AFX_DATA_INIT(CMyDlg)
  41.     m_SelectedItem = "";
  42.     //}}AFX_DATA_INIT
  43. }
  44.  
  45. void CMyDlg::DoDataExchange(CDataExchange* pDX)
  46. {
  47.     CDialog::DoDataExchange(pDX);
  48.     //{{AFX_DATA_MAP(CMyDlg)
  49.     DDX_LBString(pDX, IDC_LIST1, m_SelectedItem);
  50.     //}}AFX_DATA_MAP
  51. }
  52.  
  53. BEGIN_MESSAGE_MAP(CMyDlg, CDialog)
  54.     //{{AFX_MSG_MAP(CMyDlg)
  55.     ON_BN_CLICKED(IDC_DELETE_ITEM, OnDeleteItem)
  56.     //}}AFX_MSG_MAP
  57. END_MESSAGE_MAP()
  58.  
  59.  
  60. /////////////////////////////////////////////////////////////////////////////
  61. // CMyDlg message handlers
  62.  
  63. BOOL CMyDlg::OnInitDialog()
  64. {
  65.     CDialog::OnInitDialog();
  66.     
  67.     // TODO: Add extra initialization here
  68.  
  69.    //////////////////////
  70.    // MY CODE STARTS HERE
  71.    //////////////////////
  72.  
  73.  
  74.    // Update the m_TotalItem variable.
  75.    m_TotalItems = 6;
  76.  
  77.    // Fill the 6 items of the list box.
  78.    for (int i=0; i<=5; i++ )
  79.        {
  80.        SendDlgItemMessage(IDC_LIST1,
  81.                           LB_ADDSTRING,
  82.                           0,
  83.                 (LPARAM)(LPSTR)(const char *)m_Item[i]);
  84.        }
  85.  
  86.    // Highlight an item in the list.
  87.    SendDlgItemMessage(IDC_LIST1,
  88.                       LB_SETCURSEL,
  89.                       m_CurrentSelectedItem,
  90.                       0);
  91.  
  92.  
  93.    ////////////////////
  94.    // MY CODE ENDS HERE
  95.    ////////////////////
  96.  
  97.  
  98.     
  99.     return TRUE;  // return TRUE  unless you set the focus to a control
  100. }
  101.  
  102. void CMyDlg::OnOK()
  103. {
  104.     // TODO: Add extra validation here
  105.  
  106.      //////////////////////
  107.      // MY CODE STARTS HERE
  108.      //////////////////////
  109.  
  110.      // Update m_CurrentSelectedItem with the currently
  111.      // highlighted item.
  112.      m_CurrentSelectedItem =
  113.            (int) SendDlgItemMessage(IDC_LIST1,
  114.                                     LB_GETCURSEL,
  115.                                     0,
  116.                                     0);
  117.  
  118.      ////////////////////
  119.      // MY CODE ENDS HERE
  120.      ////////////////////
  121.  
  122.  
  123.     
  124.     CDialog::OnOK();
  125. }
  126.  
  127. void CMyDlg::OnDeleteItem()
  128. {
  129.     // TODO: Add your control notification handler code here
  130.  
  131.     //////////////////////
  132.     // MY CODE STARTS HERE
  133.     //////////////////////
  134.  
  135.     // Delete item 1 from the list box.
  136.     SendDlgItemMessage(IDC_LIST1,
  137.                        LB_DELETESTRING,
  138.                        1,
  139.                        0);
  140.  
  141.  
  142.     // Update the m_TotalItems variable with the total
  143.     // number of items.
  144.     m_TotalItems =
  145.       (int) SendDlgItemMessage(IDC_LIST1,
  146.                                LB_GETCOUNT,
  147.                                0,
  148.                                0);
  149.  
  150.     ////////////////////
  151.     // MY CODE ENDS HERE
  152.     ////////////////////
  153.  
  154. }
  155.