home *** CD-ROM | disk | FTP | other *** search
- // mydlg.cpp : implementation file
- //
-
- #include "stdafx.h"
- #include "mycombo.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)
- {
- //{{AFX_DATA_INIT(CMyDlg)
- m_SelectedItem = "";
- //}}AFX_DATA_INIT
-
- //////////////////////
- // MY CODE STARTS HERE
- //////////////////////
-
- m_CurrentSelectedItem = 3;
-
- 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
- ////////////////////
-
- }
-
- void CMyDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CMyDlg)
- DDX_CBString(pDX, IDC_COMBO1, m_SelectedItem);
- //}}AFX_DATA_MAP
- }
-
- BEGIN_MESSAGE_MAP(CMyDlg, CDialog)
- //{{AFX_MSG_MAP(CMyDlg)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
-
-
- /////////////////////////////////////////////////////////////////////////////
- // CMyDlg message handlers
-
- BOOL CMyDlg::OnInitDialog()
- {
- CDialog::OnInitDialog();
-
- // TODO: Add extra initialization here
-
- //////////////////////
- // MY CODE STARTS HERE
- //////////////////////
-
- // Fill the items of the list.
- for (int i=0; i<=5; i++ )
- {
- SendDlgItemMessage(IDC_COMBO1,
- CB_ADDSTRING,
- 0,
- (LPARAM)(LPSTR)(const char *)m_Item[i]);
- }
-
- // Set the selected item to the third item.
- SendDlgItemMessage(IDC_COMBO1,
- CB_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
- //////////////////////
-
- m_CurrentSelectedItem =
- (int) SendDlgItemMessage(IDC_COMBO1,
- CB_GETCURSEL,
- 0,
- 0);
-
- if ( m_CurrentSelectedItem == CB_ERR )
- {
- MessageBox ( "Nothing is selected in the list. Forcing Item 3" );
-
- // Set the selected item to the third item.
- m_CurrentSelectedItem = 3;
-
- }
-
- ////////////////////
- // MY CODE ENDS HERE
- ////////////////////
-
- CDialog::OnOK();
- }
-