BCX_LISTBOX function

Purpose:

BCX_LISTBOX creates a listbox that sorts strings in the list box alphabetically. The parent window receives an input message whenever the user clicks or double-clicks a string. The list box has borders on all sides.

Syntax:

hCtl = BCX_LISTBOX(Text AS STRING, _
               hwndParent AS HWND, _
                hCtlID AS INTEGER, _
                  Xpos AS INTEGER, _
                  Ypos AS INTEGER, _
                 Width AS INTEGER, _
                Height AS INTEGER  _
           [, WinStyle AS INTEGER] _
         [, ExWinStyle AS INTEGER])

Return Value:

  • Data type: HWND
    hCtl The handle of the new listbox if the function succeeds. If the function fails, the return value is NULL.

Parameters:

  • Data type: STRING
    Text Not used.
  • Data type: HWND
    hwndParent The handle of the parent window of the listbox being created.
  • Data type: INTEGER
    hCtlID Specifies the identifier of the listbox being created. The identifier is an integer value used by the listbox being created to notify its parent about events. The identifier must be unique for each listbox created with the same parent window.
  • Data type: INTEGER
    Xpos Specifies the initial horizontal x-coordinate value of the upper-left corner location of the listbox being created relative to the upper-left corner of the parent window's client area.
  • Data type: INTEGER
    Ypos Specifies the initial vertical y-coordinate value of the upper-left corner location of the listbox being created relative to the upper-left corner of the parent window's client area.
  • Data type: INTEGER
    Width Specifies the width, in device units or, if the PIXELS optional parameter was specified in the GUI statement, in pixels, of the listbox being created.
  • Data type: INTEGER
    Height Specifies the height, in device units or, if the PIXELS optional parameter was specified in the GUI statement, in pixels, of the listbox being created.
  • Data type: INTEGER
    WinStyle [OPTIONAL] If the WinStyle parameter is used, the default Window Style for a BCX_LISTBOX control, LBS_STANDARD | WS_CHILD | WS_VISIBLE | LBS_SORT | WS_VSCROLL | WS_TABSTOP, is replaced with the value in WinStyle. Specifying a WinStyle of NOSORT causes the resulting ListBox control to not sort its contents. During translation, BCX replaces NOSORT with "WS_CHILD | WS_VISIBLE | WS_VSCROLL". For more information, visit the Microsoft List Box Styles webpage and the Microsoft Window Styles webpage
  • Data type: INTEGER
    ExWinStyle [OPTIONAL] The default Extended Window Style for a BCX_LISTBOX control is WS_EX_CLIENTEDGE. For more information, visit the Microsoft Extended Window Styles webpage.

Remarks:

The default window Style for a BCX_LISTBOX control also can be changed by using the MODSTYLE function.

Example:

Here is a complete example using the BCX_LISTBOX function.

GUI "BCX_LISTBOX", PIXELS

GLOBAL Form1 AS HWND
GLOBAL List1 AS HWND

MACRO ID_Form1 = 0
MACRO ID_List1 = 1

SUB FORMLOAD
  Form1 = BCX_FORM("A BCX Listbox", 102, 88, 396, 338)
  List1 = BCX_LISTBOX("", Form1, ID_List1, 72, 52, 236, 204)

  '**************************************************************************
  SendMessage(List1, LB_ADDSTRING,0,"Annealed Glass")
  SendMessage(List1, LB_ADDSTRING,0,"Themerally Tempered Glass")
  SendMessage(List1, LB_ADDSTRING,0,"Polycarbonate")
  SendMessage(List1, LB_ADDSTRING,0,"Laminated Themerally Tempered Glass")
  SendMessage(List1, LB_ADDSTRING,0,"Laminated Semi-Tempered Glass")
  SendMessage(List1, LB_ADDSTRING,0,"Laminated Annealed Glass")
  '**************************************************************************

  CENTER(Form1)
  SHOW (Form1)
END SUB

BEGIN EVENTS
  SELECT CASE CBMSG
  CASE WM_COMMAND
    IF CBCTL = ID_List1 THEN
      IF CBCTLMSG = LBN_SELCHANGE THEN
        CALL List1_Click(ID_List1)
        EXIT FUNCTION
      END IF
    END IF
  END SELECT
END EVENTS

SUB List1_Click (Id AS INTEGER)
  DIM RAW HndlWnd AS HWND
  DIM RAW cSel, Buffer$
  HndlWnd = GetDlgItem(Form1,Id)
  cSel = SendMessage(HndlWnd,LB_GETCURSEL,0,0)
  Buffer$ = SPACE$(255)
  SendMessage(HndlWnd,LB_GETTEXT,cSel,Buffer$)
  SetWindowText(Form1, Buffer$)
END SUB ' List1_Click

For another example of the BCX_LISTBOX function see Demo.bas.