A combo box consists of a list box combined with either a static control or edit control. it is represented by CComboBox class. The list-box portion of the control may be displayed at all times or may only drop down when the user selects the drop-down arrow next to the control.
Sr.No.
Name & Description
1
AddString
Adds a string to the end of the list in the list box of a combo box, or at the sorted position for list boxes with the CBS_SORT style.
2
Clear
Deletes (clears) the current selection, if any, in the edit control.
3
CompareItem
Called by the framework to determine the relative position of a new list item in a sorted ownerdrawn combo box.
4
Copy
Copies the current selection, if any, onto the Clipboard in CF_TEXT format.
5
Create
Creates the combo box and attaches it to the CComboBox object.
6
Cut
Deletes (cuts) the current selection, if any, in the edit control and copies the deleted text onto the Clipboard in CF_TEXT format.
7
DeleteItem
Called by the framework when a list item is deleted from an owner-drawn combo box.
8
DeleteString
Deletes a string from the list box of a combo box.
9
Dir
Adds a list of file names to the list box of a combo box.
10
DrawItem
Called by the framework when a visual aspect of an owner-drawn combo box changes.
11
FindString
Finds the first string that contains the specified prefix in the list box of a combo box.
12
FindStringExact
Finds the first list-box string (in a combo box) that matches the specified string.
13
GetComboBoxInfo
Retrieves information about the CComboBox object.
14
GetCount
Retrieves the number of items in the list box of a combo box.
15
GetCueBanner
Gets the cue text that is displayed for a combo box control.
16
GetCurSel
Retrieves the index of the currently selected item, if any, in the list box of a combo box.
17
GetDroppedControlRect
Retrieves the screen coordinates of the visible (dropped down) list box of a drop-down combo box.
18
GetDroppedState
Determines whether the list box of a drop-down combo box is visible (dropped down).
19
GetDroppedWidth
Retrieves the minimum allowed width for the drop-down list-box portion of a combo box.
20
GetEditSel
Gets the starting and ending character positions of the current selection in the edit control of a combo box.
21
GetExtendedUI
Determines whether a combo box has the default user interface or the extended user interface
22
GetHorizontalExtent
Returns the width in pixels that the list-box portion of the combo box can be scrolled horizontally.
23
GetItemData
Retrieves the applicationsupplied 32-bit value associated with the specified combo-box item.
24
GetItemDataPtr
Retrieves the applicationsupplied 32-bit pointer that is associated with the specified combo-box item.
25
GetItemHeight
Retrieves the height of list items in a combo box.
26
GetLBText
Gets a string from the list box of a combo box.
27
GetLBTextLen
Gets the length of a string in the list box of a combo box.
28
GetLocale
Retrieves the locale identifier for a combo box.
29
GetMinVisible
Gets the minimum number of visible items in the drop-down list of the current combo box.
30
GetTopIndex
Returns the index of the first visible item in the list-box portion of the combo box.
31
InitStorage
Preallocates blocks of memory for items and strings in the listbox portion of the combo box.
32
InsertString
Inserts a string into the list box of a combo box.
33
LimitText
Limits the length of the text that the user can enter into the edit control of a combo box.
34
MeasureItem
Called by the framework to determine combo box dimensions when an ownerdrawn combo box is created
35
Paste
Inserts the data from the Clipboard into the edit control at the current cursor position. Data is inserted only if the Clipboard contains data in CF_TEXT format.
36
ResetContent
Removes all items from the list box and edit control of a combo box.
37
SelectString
Searches for a string in the list box of a combo box and, if the string is found, selects the string in the list box and copies the string to the edit control.
38
SetCueBanner
Sets the cue text that is displayed for a combo box control.
39
SetCurSel
Selects a string in the list box of a combo box.
40
SetDroppedWidth
Sets the minimum allowed width for the drop-down list-box portion of a combo box.
41
SetEditSel
Selects characters in the edit control of a combo box.
42
SetExtendedUI
Selects either the default user interface or the extended user interface for a combo box that has the CBS_DROPDOWN or CBS_DROPDOWNLIST style.
43
SetHorizontalExtent
Sets the width in pixels that the list-box portion of the combo box can be scrolled horizontally.
44
SetItemData
Sets the 32-bit value associated with the specified item in a combo box.
45
SetItemDataPtr
Sets the 32-bit pointer associated with the specified item in a combo box.
46
SetItemHeight
Sets the height of list items in a combo box or the height of the edit-control (or static-text) portion of a combo box.
47
SetLocale
Sets the locale identifier for a combo box.
48
SetMinVisibleItems
Sets the minimum number of visible items in the drop-down list of the current combo box.
49
SetTopIndex
Tells the list-box portion of the combo box to display the item with the specified index at the top.
50
ShowDropDown
Shows or hides the list box of a combo box that has the CBS_DROPDOWN or CBS_DROPDOWNLIST style.
Here is the list of messages mapping for Combobox control −
Message
Map entry
Description
CBN_DBLCLK
ON_CBN_DBLCLK( <id>, <memberFxn> )
The user double-clicks a string in the list box of a combo box.
CBN_DROPDOWN
ON_CBN_DROPDOWN( <id>, <memberFxn> )
The list box of a combo box is about to drop down (be made visible).
CBN_EDITCHANGE
ON_CBN_EDITCHANGE( <id>, <memberFxn> )
The user has taken an action that may have altered the text in the editcontrol portion of a combo box.
CBN_EDITUPDATE
ON_CBN_EDITUPDATE( <id>, <memberFxn> )
The edit-control portion of a combo box is about to display altered text.
CBN_KILLFOCUS
ON_CBN_KILLFOCUS( <id>, <memberFxn> )
The combo box is losing the input focus.
CBN_SELCHANGE
ON_CBN_SELCHANGE( <id>, <memberFxn> )
The selection in the list box of a combo box is about to be changed as a result of the user either clicking in the list box or changing the selection by using the arrow keys.
CBN_SETFOCUS
ON_CBN_SETFOCUS( <id>, <memberFxn> )
The combo box receives the input focus.
Let us look into an example of Radio button by creating a new MFC dialog based application.
Step 1 − Drag a Combo box and remove the Caption of Static Text control.
Step 2 − Add a control variable m_comboBoxCtrl for combobox and value variable m_strTextCtrl for Static Text control.
Step 3 − Add event handler for selection change of combo box.
Step 4 − Add the following code in OnInitDialog() to load the combo box.
for (int i = 0; i<10; i++) {
str.Format(_T("Item %d"), i);
m_comboBoxCtrl.AddString(str);
}
Step 5 − Here is the implementation of event handler.
void CMFCComboBoxDlg::OnCbnSelchangeCombo1() {
// TODO: Add your control notification handler code here
m_comboBoxCtrl.GetLBText(m_comboBoxCtrl.GetCurSel(), m_strTextCtrl);
UpdateData(FALSE);
}
Step 6 − When the above code is compiled and executed, you will see the following output.
Step 7 − When you select any item then it will be displayed on the Text Control.
To Continue Learning Please Login
Login with Google