ListBox Control

Purpose

Creates a ListBox control in the current active form, window, or dialog.

Syntax

ListBox text$, id%, x, y, w, h[, style%]

text$:control text
id%:control identifier
x, y, w, h:iexp
style%:the control styles

Description

The control is a rectangle containing a list of strings (such as filenames) from which the user can select.

Style Meaning
LBS_NOTIFY ($0001) sends a message to the parent window when the user selects an entry by clicking.
LBS_SORT ($0002) performs an alphabetical sort of several alternatives.
LBS_NOREDRAW ($0004) prevents ListBox redraw after receiving changes.
LBS_MULTIPLESEL($0008) after an initial selection (the entry is displayed in reverse) enables additional selections. The number of selections is not limited.
LBS_OWNERDRAWFIXED($0010) specifies a ListBox, whose input must be performed by the calling task. All items within this ListBox have the same height.
LBS_OWNERDRAWVARIABLE ($0020) similar to LBS_OWNERDRAWFIXED, except that the items can have a variable height.
LBS_HASSTRINGS ($0040) used when items within a ListBox are composed of strings. The ListBox refers items to strings by using pointers.
LBS_USETABSTOPS ($0080) displays a multi-column ListBox, whereby the individual columns are located at predefined tab positions.
LBS_NOINTEGRALHEIGHT($0100) makes the size of the ListBox the size specified by application.
LBS_MULTICOLUMN($0200) specifies a multi-line ListBox, which can scroll horizontally.
LBS_WANTKEYBOARDINPUT($0400) allows for assignment of special keys or key combinations (Hotkeys) to entries in a Listbox.
LBS_EXTENDEDSEL($0800) specifies a ListBox, whereby multiple entries can be selected by using the Shift key and mouse clicks.
LBS_STANDARD creates a ListBox with the following attributes: LBS_NOTIFY | LBS_SORT | WS_VSCROLL | WS_BORDER

If you do not specify a style, the default style is LBS_NOTIFY | WS_BORDER.

The command creates a control without an OCX wrapper; so it and cannot be handled using properties, methods, and event subs. When used in a form the WM_COMMAND message should be handled in the form's _Message sub.

Example

Dlg 3D On

Local x%, sel$

Dialog # 1, 10, 10, 200, 310, "Test"

ListBox "Listbox", 10, 20, 20, 150, 200

DefPushButton "OK", IDOK, 10, 250, 80, 25, WS_TABSTOP

PushButton "CANCEL", IDCANCEL, 110, 250, 64, 24, WS_TABSTOP

EndDialog

Data "GFA-BASIC 32"

Data "GFA-BASIC for MS-DOS"

Data "GFA-BASIC for Windows"

Data "GFA-BASIC for Atari"

Data "GFA-BASIC for Amiga"

For x% = 0 To 4

Read sel$

~SendMessage(Dlg(1, 10), LB_ADDSTRING, 0, sel$)

_Win$(DlgItem(1, 10)) = sel$

Next

ShowDialog # 1

Do

Sleep

Until Me Is Nothing

Dlg 3D Off

 

Sub Dlg_1_Message(hWnd%, Mess%, wParam%, lParam%)

Switch Mess

Case WM_COMMAND

Switch LoWord(wParam)

Case 10

Trace "Notification code: " & HiWord(wParam)

Case IDOK, IDCANCEL

CloseDialog # 1

EndSwitch

EndSwitch

EndSub

Remarks

This command is particular useful for a dialog box in a GLL, because a GLL doesn't support OCX controls.

With the general Control statement any control type can be created.

See Also

Control, AnimateCtrl, AutoCheckBox, AutoRadioButton, CheckBox, ComboBox, CText, Dialog, DefPushButton, EditText, GroupBox, HeaderCtrl, ListBox, ListViewCtrl, LText, ProgressCtrl, PushButton, RadioButton, RichEditCtrl, RText, ScrollBar, StatusCtrl, TabCtrl, ToolBarCtrl, TrackBarCtrl, TreeViewCtrl, UpDownCtrl

{Created by Sjouke Hamstra; Last updated: 12/10/2014 by James Gaite}