Friday, December 15

Combo Box Functions

Google+ Pinterest LinkedIn Tumblr +

Windows Predefined Controls – Part 26
Volume – Windows User Interface

Introduction
This is part 26 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 combo box functions.

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.

The DlgDirListComboBox Function
This function replaces the contents of a combo box with the names of the subdirectories and files in a specified directory. You can choose the list of names by specifying a set of file attributes. The list of names can include mapped drive letters. The prototype of the function is:

int DlgDirListComboBox(
  __in     HWND hDlg,
  __inout  LPTSTR lpPathSpec,
  __in     int nIDComboBox,
  __in     int nIDStaticPath,
  __in     UINT uFiletype
);

__in means input to the function. __out means output to the function. __inout means input or output to the function.

hDlg is a handle to the dialog box (window) that contains the combo box.

pPathSpec is of type LPTSTR and it is a pointer to a buffer containing a null-terminated string that specifies an absolute path, relative path, or file name. An absolute path can begin with a drive letter (for example, e:\) or a UNC name (for example, \\machinename\sharename). If the string does not specify a directory, the function searches the current directory. The function splits the string into a directory and a file name. The function searches the directory for names that match the file name. If the string includes a file name, the file name must have at least one wildcard character (? or *). If the string does not include a file name, the function behaves as if you had specified the asterisk wildcard character (*) as the file name. All names in the specified directory that match the file name and have the attributes specified by the uFiletype parameter (see below) are added to the list displayed in the combo box.

nIDComboBox is of  type, int. It is the identifier of a combo box in the hDlg dialog box (window). If this parameter is zero, DlgDirListComboBox does not attempt to fill a combo box.

nIDStaticPath is of type int. It is the identifier of a static control in the hDlg dialog box. DlgDirListComboBox sets the text of this control to display the current drive and directory. This parameter can be zero if you do not want to display the current drive and directory.

uFiletype is of type UINT. It is a set of bit (1 or 0) flags that specifies the attributes of the files or directories to be added to the combo box. This parameter can be a combination of the following values:

DDL_ARCHIVE: Includes archived files.
DDL_DIRECTORY: Includes subdirectories, which are enclosed in square brackets ([ ]).
DDL_DRIVES: All mapped drives are added to the list. Drives are listed in the form [-x-], where x is the drive letter.
DDL_EXCLUSIVE: Includes only files with the specified attributes. By default, read-write files are listed even if DDL_READWRITE is not specified.
DDL_HIDDEN: Includes hidden files.
DDL_READONLY: Includes read-only files.
DDL_READWRITE: Includes read-write files with no additional attributes. This is the default setting.
DDL_SYSTEM: Includes system files.
DDL_POSTMSGS: If this flag is set, DlgDirListComboBox uses the PostMessage function (see later) to send messages to the combo box. If this flag is not set, DlgDirListComboBox uses the SendMessage function.

If the function succeeds, the return value is nonzero. If the function fails, the return value is zero. For example, if the string specified by lpPathSpec is not a valid path, the function fails. To get extended error information, call GetLastError (see later).

The DlgDirSelectComboBoxEx Function
This function retrieves the current selection from a combo box filled using the DlgDirListComboBox function. This selection is interpreted as a drive letter, a file, or a directory name. The prototype of the function is:

BOOL DlgDirSelectComboBoxEx(
  __in   HWND hDlg,
  __out  LPTSTR lpString,
  __in   int nCount,
  __in   int nIDComboBox
);

hDlg is of type HWND. It is a handle to the dialog box (window) that contains the combo box.

lpString is of type LPTSTR. It is a pointer to the buffer that receives the selected path.

nCount is of type int. It is the length, in characters, of the buffer pointed to by the lpString parameter. The application creates the buffer first before using this function.

nIDComboBox is of type int. It is the integer identifier of the combo box control in the dialog box.

The return value is nonzero, if the current selection is a directory name. If the current selection is not a directory name, the return value is zero. To get extended error information, call GetLastError (see later).

The GetComboBoxInfo Function
This function retrieves information about the specified combo box. The prototype of the function is:

BOOL GetComboBoxInfo(
  __in   HWND hwndCombo,
  __out  PCOMBOBOXINFO pcbi
);

hwndCombo is of type HWND. It is a handle to the combo box.

pcbi is of type type, PCOMBOBOXINFO. It is a pointer to a COMBOBOXINFO structure (see later) that receives the information. You must set COMBOBOXINFO.cbSize (see later) before calling this function.

The return value is of type BOOL. If the function succeeds, the return value is nonzero. If the function fails, the return value is zero. To get extended error information, call GetLastError (see later).

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

Chrys

To arrive at any of the parts of this series, just type the corresponding title below in the Search Box of this page and click Search (use menu if available):

List Box Functions
Windows Combo Box
Combo Box Styles
Combo Box Notifications
Combo Box Messages
Creating Combo Boxes
Combo Box functions
Windows Scroll Bar
 

Share.

About Author

Leave A Reply