Create an SDI windows program using AppExpert. Your program should use a TWindow as it's base window. Next create a menu List Box with a single choice Test List Box. This should execute a dialog box that contains a list box similar to the one shown here.
Use the resource workshop to create this dialog box. Make sure you match these listbox settings.
Create a class for the dialog box and an instance variable for the list box. We will create an array in the main window and pass it to the dialog as the first parameter in the constructor. The second parameter for the constructor should be the transfer buffer pointer.
MyDialog::MyDialog (Array< string > &ml,MyDialogXfer *tb,TWindow* parent, TResId resId, TModule* module):
TDialog(parent, resId, module),myArray(ml)
{
//{{MyDialogXFER_USE}}
_listBox = new TListBox(this, IDC_MYLISTBOX);
SetTransferBuffer(tb);
//{{MyDialogXFER_USE_END}}
// INSERT>> Your constructor code here.
}
The constructor for the main window and the handler for the menu item should look like this.
Inclass2Window::Inclass2Window (TWindow* parent, const char far* title, TModule* module)
: TWindow(parent, title, module)
{
// INSERT>> Your constructor code here.
myList.insertItem("First 1000");//tab between string and number.
myList.insertItem("Second 2000");
myList.insertItem("Third 3000");
}
void Inclass2Window::cmTestListBox ()
{
// INSERT>> Your code here.
MyDialogXfer tb;
ArrayIterator< string > next(myList);
while (next)
{
tb._listBox.AddString(next().c_str());
next++;
}
MyDialog(myList,&tb,this).Execute();
}
Finally, under the instance variable for the listbox in the dialog box, select the event handler LBN_DBLCLK (left button double click). Add the handler that looks like this:
void MyDialog::LBNDblclk ()
{
// INSERT>> Your code here.
int where=_listBox->GetSelIndex();
MessageBox( myArray[where].c_str(),"Got This One");
}
To get a complete version of this program click here.