Broad Network


List Box Functions

Windows Predefined Controls – Part 20

Volume - Windows User Interface

Forward: In this part of the series, we look at List Box Functions.

By: Chrysanthus Date Published: 29 Aug 2012

Introduction

This is part 20 of my series, Windows Predefined Controls. In order to understand this tutorial, you most have read all the previous tutorials of the series. In this part of the series, we look at List 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 DlgDirList Function
This function replaces whatever items were in a list box with the names of the subdirectories and files of a specified directory. You can filter the list of names by specifying a set of file attributes (see below). The list can optionally include mapped drives. The function prototype is:

int DlgDirList(HWND hDlg, LPTSTR lpPathSpec, int nIDListBox, int nIDStaticPath, UINT uFileType);

hDlg is the handle of the window (dialog box) that contains the list box.

lpPathSpec which is of type LPTSTR is a pointer to a buffer (char array) containing a null-terminated string that specifies an absolute path, relative path, or filename. 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 separates the string into a directory (if specified) and a filename, and then works on the two parts. The function searches the directory for names that match the filename. The function also searches the directory for subdirectories. If the string includes a filename, the filename must contain at least one wildcard character (? or *). If the string does not include a filename, the function behaves as if you had specified the asterisk wildcard character (*) as the filename. All names in the specified directory that match the filename and have the attributes specified by the uFileType parameter (see below) are added to the list box.

nIDListBox, which is of type, int is the identifier of a list box in the hDlg dialog box (window). If this parameter is zero, DlgDirList does not attempt to fill a list box.

nIDStaticPath: Conventionally, you need a static control to be displayed along side the list box that shows the directory listing. You have to create the static control independently. nIDStaticPath, which is of type, int is the identifier of such a static control in the hDlg dialog box (window). The DlgDirList function displays the current drive and directory in this static control. Set this parameter to zero if you do not want the current drive and directory to be displayed.

uFileType, which is of type, UINT specifies the attributes of the files or directories to be added to the list box. It can be one or more of the following values:

DDL_ARCHIVE: Includes archived files.
DDL_DIRECTORY: Includes subdirectories. Subdirectory names 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 set, DlgDirList uses the PostMessage (see later) function to send messages to the list box. If not set, DlgDirList uses the SendMessage function.

If the function succeeds, the return value is nonzero. If the function fails, the return value is zero.

The DlgDirSelectEx Function
We are concerned here with a single selection list box. In this list a user would select one item. If the list box has been filled by the DlgDirList function and the selection is a drive letter, filename, or directory name, then the DlgDirSelectEx Function would retrieve the current selection.

The prototype of the function is:

BOOL DlgDirSelectEx(
  __in   HWND hDlg,
  __out  LPTSTR lpString,
  __in   int nCount,
  __in   int nIDListBox
);

__in means input to the function and __out means output from the function.

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

lpString is a pointer to a buffer (char array) that receives the selected path. You should create the buffer before using this function.

nCount is the length, in TCHARs (characters), of the buffer (char array) pointed to by lpString. You should create the buffer before using this function.

nIDListBox is the identifier of the list box in the dialog box.

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

The GetListBoxInfo Function
This function retrieves the number of items per column in a specified list box. The prototype is:

DWORD GetListBoxInfo(HWND hwnd);

hwnd is the handle to the list box whose number of items per column is to be retrieved. The return value is of type, DWORD, which means, Double Word (32 bits = 16 bits + 16 bits). The returned value is the number of items per column.

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