Broad Network


Windows Combo Box

Windows Predefined Controls – Part 21

Volume - Windows User Interface

Forward: In this part of the series, we look at Windows Combo Box.

By: Chrysanthus Date Published: 29 Aug 2012

Introduction

This is part 21 of my series, Windows Predefined Controls. In order to understand this tutorial, you must have read all the previous tutorials of the series. In this part of the series, we look at Windows Combo Box.

Note: If you cannot see the code or if you think anything is missing (broken link, image absent), just contact me at forchatrans@yahoo.com. That is, contact me for the slightest problem you have about what you are reading.

What is a Combo Box?
A combo box is a control that consist of a list box and either an edit control or a static control above it. With the combo box only one item can be selected; that is, the user cannot select more than one item in the list box at the same time. When the item is selected it appears in the edit control or the static control, depending on which one the combo box is using. All controls are child windows.

The edit control or the static control above the list box is called the Selection Field. The list box of the combo box is sometimes simply called the list. The list presents the options that a user can select, and the selection field displays the option selected. The option selected is called the current selection.

If the selection field is an edit control, the user can type what he wants directly into the edit control. What he types into the edit control does not necessarily have to be found in the list.

In this series, we deal only with items in the list that are strings.

Zero-Based Indexing
The items in the list box are numbered counting from zero at the first item. Each of these numbers is called an index

Types of Combo Boxes
There are three types of combo boxes: Simple, Drop Down and Drop Down List.

The Simple Combo Box
This type of combo box has a list box and an edit control above it. You see one or more elements always in the list. When the user selects an item in the list, it is highlighted, and then you also see the selected item in the edit control. The user can also type something into the edit control that is not in the list. This type of combo box uses the CBS_SIMPLE combo box style.

Of course the list of this type of combo box can have a scroll bar. At all times you see the selection field and the list, for this combo box type.

The Drop Down Combo Box
With this type of combo box, you see only the selection field at all times. The selection field has a drop down arrow button on its right. When the user clicks the drop down arrow, he sees the list dropped down (displayed below the selection field). Then the user can select an item in the list. When the item is selected, the drop down list closes up and the selected item appears in the selection field. The selection field here is an edit control. The drop down list can have a scroll bar.

The user can also type something into the edit control that is not in the list, without dropping down the list. This type of combo box uses the CBS_DROPDOWN combo box style.

The Drop Down List Combo Box
This type of combo box is similar to the drop down combo box, described above, except that its selection field is a static control and not an edit control. This type of combo box uses the CBS_DROPDOWNLIST combo box style.

Directory List
A combo box can have lists of all sorts. A list of particular interest is the listing of a directory. We shall see more about this later.

Data Associated with List Items
An application can have associated data with the list items in a combo box. The datum associated with a list item is of type, DWORD, which means, Double Word (8 bits form a byte, 16 bits form a word and 32 bits form a DWORD). We shall see more about this later.

The Extended User Interface
Drop-down combo boxes and drop-down list combo boxes support an alternative keyboard interface called the Extended User Interface. By default and without the extended user interface, the F4 key opens or closes the list, and the Down Arrow Key changes the current selection. In a combo box with the extended user interface, however, the F4 key is disabled and pressing the Down Arrow key opens the drop-down list. In addition, the mouse wheel, which normally scrolls through the items in the list, does not have any function when the extended UI is set. More on this later!

Cue Banners
When an application starts and before any item in the list is selected, you can have text such as “Select Item from Below” displayed in the edit control of a combo box. This is an example of a cue banner. This gives a hint to the user as to what he should do with the combo box. As soon as the user selects an item in the list or as soon as he starts typing into the edit control, the cue banner disappears. That is the behavior of the cue banner. We shall see more on this later.

Creating a Combo Box
You can create a combo box using the CreateWindowEx function. The class is provided by the operating system and it is called, COMBOBOX. The style consists of WS_CHILD and CBS_SIMPLE or CBS_DROPDOWN or CBS_DROPDOWNLIST as a minimum. The rest of the arguments for the CreateWindowEx function are like those in the creation of other controls. I have dedicated a whole tutorial on the creation of combo boxes. Before we arrive at that tutorial, we shall first look at combo box styles, combo box notifications and combo box messages, each as a tutorial.

That is it for this part of the series. We stop here and continue in the next part.

Chrys

Related Courses

C++ Course
Relational Database and Sybase
Windows User Interface
Computer Programmer – A Jack of all Trade – Poem
NEXT

Comments

Become the Writer's Fan
Send the Writer a Message