|
Testing the Program as you Progress
- To test the result, anytime, press Ctrl + F5.
Creating the Application
- Start Microsoft Visual C++
- On the main menu, click File -> New.
- Decide to create a Dialog Based application called ListOfCountries with a title as
List of Countries - While designing the dialog box, place a List Box control on it. Change the identifier of the list box to IDC_LIST_COUNTRIES
- Place an Edit Box on the dialog. Call it IDC_LISTDBLCLK
- Right-click the List Box and click ClassWizard...
- Click the Member Variables property sheet.
- Double-click IDC_LISTCOUNTRIES to Add a Variable
- Set the Member Variable Name to m_ListCountries
- In the Category combo box, select Control
- Click OK
- Also Add a Variable for the IDC_LISTDBLCLK control and named m_ListResult based on CString
Adding Items to a List Box
- In the OnInitDialog() function of the dialog box, initialize the list box as follows:
// TODO: Add extra initialization here
m_ListCountries.AddString("Afghanistan");
m_ListCountries.AddString("Costa Rica");
m_ListCountries.AddString("Spain");
m_ListCountries.AddString("Angola");
m_ListCountries.AddString("Russia");
m_ListCountries.AddString("Canada");
m_ListCountries.AddString("Greece");
m_ListCountries.AddString("Morocco");
m_ListCountries.AddString("Austria");
m_ListCountries.AddString("Jamaica");
m_ListCountries.AddString("Australia");
Select an Item Using its Position
- To set the 4th item in the list box as selected, under the last AddString() function in the OnInitDialog, add the following line.
m_ListCountries.SetCurSel(3);
Transfer an Item to an Edit Box After Double-Clicking in the List
- Press Ctrl + W to access the ClassWizard.
- Click the Message Maps property sheet. In the Class Name combo box, make sure CListExoDlg is selected. In the Object IDs, click IDC_LISTCOUNTRIES
- In the Messages list, double-click LBN_DBLCLK. Change the name of the function to OnDblclkList and click OK.
- Click Edit Code and implement the function as follows
No comments:
Post a Comment