home *** CD-ROM | disk | FTP | other *** search
- // mydlg.cpp : implementation file
- //
-
- #include "stdafx.h"
- #include "mylist.h"
- #include "mydlg.h"
-
- #ifdef _DEBUG
- #undef THIS_FILE
- static char BASED_CODE THIS_FILE[] = __FILE__;
- #endif
-
- /////////////////////////////////////////////////////////////////////////////
- // CMyDlg dialog
-
-
- CMyDlg::CMyDlg(CWnd* pParent /*=NULL*/)
- : CDialog(CMyDlg::IDD, pParent)
- {
-
- //////////////////////
- // MY CODE STARTS HERE
- //////////////////////
-
- m_CurrentSelectedItem = 3;
-
- m_TotalItems = 6;
-
- m_Item[0] = "Item 0";
- m_Item[1] = "Item 1";
- m_Item[2] = "Item 2";
- m_Item[3] = "Item 3";
- m_Item[4] = "Item 4";
- m_Item[5] = "Item 5";
-
- ////////////////////
- // MY CODE ENDS HERE
- ////////////////////
-
- //{{AFX_DATA_INIT(CMyDlg)
- m_SelectedItem = "";
- //}}AFX_DATA_INIT
- }
-
- void CMyDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CMyDlg)
- DDX_LBString(pDX, IDC_LIST1, m_SelectedItem);
- //}}AFX_DATA_MAP
- }
-
- BEGIN_MESSAGE_MAP(CMyDlg, CDialog)
- //{{AFX_MSG_MAP(CMyDlg)
- ON_BN_CLICKED(IDC_DELETE_ITEM, OnDeleteItem)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
-
-
- /////////////////////////////////////////////////////////////////////////////
- // CMyDlg message handlers
-
- BOOL CMyDlg::OnInitDialog()
- {
- CDialog::OnInitDialog();
-
- // TODO: Add extra initialization here
-
- //////////////////////
- // MY CODE STARTS HERE
- //////////////////////
-
-
- // Update the m_TotalItem variable.
- m_TotalItems = 6;
-
- // Fill the 6 items of the list box.
- for (int i=0; i<=5; i++ )
- {
- SendDlgItemMessage(IDC_LIST1,
- LB_ADDSTRING,
- 0,
- (LPARAM)(LPSTR)(const char *)m_Item[i]);
- }
-
- // Highlight an item in the list.
- SendDlgItemMessage(IDC_LIST1,
- LB_SETCURSEL,
- m_CurrentSelectedItem,
- 0);
-
-
- ////////////////////
- // MY CODE ENDS HERE
- ////////////////////
-
-
-
- return TRUE; // return TRUE unless you set the focus to a control
- }
-
- void CMyDlg::OnOK()
- {
- // TODO: Add extra validation here
-
- //////////////////////
- // MY CODE STARTS HERE
- //////////////////////
-
- // Update m_CurrentSelectedItem with the currently
- // highlighted item.
- m_CurrentSelectedItem =
- (int) SendDlgItemMessage(IDC_LIST1,
- LB_GETCURSEL,
- 0,
- 0);
-
- ////////////////////
- // MY CODE ENDS HERE
- ////////////////////
-
-
-
- CDialog::OnOK();
- }
-
- void CMyDlg::OnDeleteItem()
- {
- // TODO: Add your control notification handler code here
-
- //////////////////////
- // MY CODE STARTS HERE
- //////////////////////
-
- // Delete item 1 from the list box.
- SendDlgItemMessage(IDC_LIST1,
- LB_DELETESTRING,
- 1,
- 0);
-
-
- // Update the m_TotalItems variable with the total
- // number of items.
- m_TotalItems =
- (int) SendDlgItemMessage(IDC_LIST1,
- LB_GETCOUNT,
- 0,
- 0);
-
- ////////////////////
- // MY CODE ENDS HERE
- ////////////////////
-
- }
-