Visual C++ and MFC Programming 2nd Edition

(Martin Jones) #1

Chapter 20: List-Based Controls Visual C++ and MFC Fundamentals


BOOL CClarksvilleIceScream2Dlg::OnInitDialog()
{
CDialog::OnInitDialog();

// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon

// TODO: Add extra initialization here
m_Topping.SetCurSel(0);
m_Scoops.SetCurSel(0);

m_Flavors.AddString("French Vanilla");
m_Flavors.AddString("Cream of Cocoa");
m_Flavors.AddString("Chocolate Chip");
m_Flavors.AddString("Cherry Coke");
m_Flavors.AddString("Butter Pecan");
m_Flavors.AddString("Chocolate Cooky");
m_Flavors.AddString("Chunky Butter");
m_Flavors.AddString("Vanilla Strawberry");
m_Flavors.AddString("Macedoine");
m_Flavors.AddString("Mint Chocolate");
m_Flavors.SetCurSel(6);

return TRUE; // return TRUE unless you set the focus to a control
}


  1. Save All


20.2.4..Combo Box Messages and Events....................................................


When you add or create a combo box, an amount of space is allocated and during the
lifetime of your application, the combo box uses some memory to processing its
assignments. If at one time there is not enough memory for these processings, the combo
box sends an ON_CBN_ERRSPACE message.

Like any control, for the user to use the combo box, it must first have focus. This can be
done by the user clicking its edit part, its list part (for a Simple combo box) or its down
pointing arrow (for a drop type combo box). When the combo box receives focus, its
sends the ON_CBN_SETFOCUS message.

Once the control has focus, if the user clicks or had clicked the edit side of the combo
box that already had a selected item, if the user starts typing, which would modify the
string of the item that was already selected, the combo box would send the
ON_CBN_EDITCHANGE message (remember that the user can change the string only
if the combo box was not created as Drop List). If the user finishes typing or changing the
string, just before the altered string is validated, the combo box sends the
ON_CBN_EDITUPDATE message.

To select an item from a drop type combo box, the user usually clicks the down pointing
arrow button to display the control’s list. When the user clicks that button, just before the
list displays, the control sends the ON_CBN_DROPDOWN message. After this click
and this message, the list part of a drop combo box displays and the user must make a
decision:
Free download pdf