Provides an easy to use virtual listbox implementation. The virtual listbox supports focus tracking, mouse hot tracking items, mouse wheel support, and user selectable coloring in addition to the standard list box features. In addition there's an implementation of logging to a window that allows logging approximately 100,000 items per second. Both include example programs.

Virtual ListBox

Following is some example creation code. Note that the dialog must be shown modelessly at least initially so that WM_MeasureItem will be dispatched correctly. If you forget this, the items will be a default height.

 
' Create the dialog 
Dialog New Pixels, 0, "Virtual List Box", , , 300, 500, %WS_OverlappedWindow Or %DS_Center Or %WS_ClipChildren, %WS_Ex_Composited To hDlg ' Put the dialog procedure in place 
Dialog Show Modeless hDlg Call DlgProc: ' Need to have to proc in place when adding controls 
' Add a virtual listbox 
ControlAddVirtualListBox hDlg, 101, %LIST_ITEM_COUNT, 24, 10, 10, 140, 480 ' After creation you can show the dialog modally if desired Dialog Show Modal hDlg Call DlgProc 
In addition you must create a function to provide values to the listbox. For example:
Function GetValueListBox1( ByVal index As Long ) As String ' Dynaically generated 
  Function = "ListBox1 " + Format$( index+1, "#,##0" )
End Function
Finally you must create a dialog procedure to dispatch a few events:
CallBack Function DlgProc Local l, w, h As Long 
  Select Case Cb.Msg 
    Case %WM_MouseLeave, %WM_DrawItem, %WM_MeasureItem 
      Select Case Cb.WParam 
        Case 101: Function = ListBoxDialogProc( Cb.Hndl, Cb.Msg, Cb.WParam, Cb.LParam, CodePtr( GetValueListBox1 ) ) 
      End Select 
  End Select
End Function

The available routines for the virtual listbox are:

Sub ListBoxSetDefaultColors( ByVal foreColor As Dword, ByVal backColor As Dword, ByVal selForeColor As Dword, ByVal selBackColor As Dword, ByVal selUnFocusBackColor As Dword, ByVal hotTrack As Dword )
Sets the colors any subsequent listbox will initially be created with

  • foreColor - Normal color of unselected text
  • backColor - Normal background color of unselected text
  • selForeColor - Foregorund text color of a selected item.
  • selBackColor - Background color of a selected item when listbox is focused or has the keyboard input.
  • selUnFocusBackColor - Background color of a selected item when the list box is not focused
  • hotTrack - Background color of the item under the mouse

Sub ListBoxSetColors( ByVal hDlg As Dword, ByVal ctrlId As Long, ByVal foreColor As Dword, ByVal backColor As Dword, ByVal selForeColor As Dword, ByVal selBackColor As Dword, ByVal selUnFocusBackColor As Dword, ByVal hotTrack As Dword )
Sets the current colors for the listbox, may be changed at any time.

  • hDlg - Handle of the parent dialog control is being added to.
  • ctrlId - Control id of the listbox to change colors on.
  • foreColor - Normal color of unselected text
  • backColor - Normal background color of unselected text
  • selForeColor - Foregorund text color of a selected item.
  • selBackColor - Background color of a selected item when listbox is focused or has the keyboard input.
  • selUnFocusBackColor - Background color of a selected item when the list box is not focused
  • hotTrack - Background color of the item under the mouse

Sub ListBoxSetCount( ByVal hDlg As Dword, ByVal ctrlId As Long, ByVal cnt As Long )
Sets the number of items in the list box

  • hDlg - Handle of the parent dialog control is being added to.
  • ctrlId - Control id of the control being added.
  • cnt - Number of items in the listbox

Sub ControlAddSimpleListBox( ByVal hDlg As Dword _ 
        , ByVal ctrlId As Long _ 
        , ByVal cnt As Long _ 
        , ByVal itemHeight As Long _ 
        , ByVal x As Long _ 
        , ByVal y As Long _ 
        , ByVal w As Long _ 
        , ByVal h As Long _ 
        , ByVal winStyle As Dword _ 
        , ByVal winStyleEx As Dword _ 
        , ByVal valueProc As Dword ) 

Creates a simple virtual listbox that display user provided strings.
  • hDlg - Handle of the parent dialog control is being added to.
  • ctrlId - Control id of the control being added.
  • cnt - Number of items initially in listbox.
  • itemHeight - Height of each item in the listbox.
  • x - Left edge of listbox.
  • y - Top edge of listbox
  • w - Width of list box
  • h - Height of list box
  • winStyle - Windows style of the listbox. %LBS_VSTANDARD, %LBS_VCHECKBOX, %LBS_VRADIO have been provided for convenience
  • winStyleEx - Extended window style for the listbox.
  • valueProc - User function to provide listbox values. Function GetValue( ByVal index as Long ) As String

Sub ControlAddDrawnListBox( ByVal hDlg As Dword _ 
        , ByVal ctrlId As Long _ 
        , ByVal cnt As Long _ 
        , ByVal itemHeight As Long _ 
        , ByVal x As Long _ 
        , ByVal y As Long _ 
        , ByVal w As Long _ 
        , ByVal h As Long _ 
        , ByVal winStyle As Dword _ 
        , ByVal winStyleEx As Dword _ 
        , ByVal drawProc As Dword ) 

Creates an owner drawn virtual listbox.
  • hDlg - Handle of the parent dialog control is being added to.
  • ctrlId - Control id of the control being added.
  • cnt - Number of items initially in listbox.
  • itemHeight - Height of each item in the listbox.
  • x - Left edge of listbox.
  • y - Top edge of listbox
  • w - Width of list box
  • h - Height of list box
  • winStyle - Windows style of the listbox. %LBS_VSTANDARD, %LBS_VCHECKBOX, %LBS_VRADIO have been provided for convenience
  • winStyleEx - Extended window style for the listbox.
  • drawProc - User function to draw listbox items. Sub DrawItem( ByVal hDlg As Dword, ByRef di As DrawItemStruct, ByVal foreClr As Dword, ByVal backClr As Dword )

Sub ListBoxGetColors( ByVal hDlg As Dword, ByVal ctrlId As Long, ByVal clr As Long, ByRef fgColor As Dword, ByRef bgColor As Dword )

Get selected colors for the listbox.
  • hDlg - Handle of the parent dialog control is being added to.
  • ctrlId - Control id of the control being added.
  • clr - Color index to retreive. One of the following may be retrieved: %ListBoxColors.Normal, %ListBoxColors.Selected, %ListBoxColors.UnFocused, %ListBoxColors.HotTrack
  • fgColor - foreground color retrieved.
  • bgColor - background color retrieved.

Logging

The available routines for logging are:

Sub LogMessage( msg As String )
Add a message to the log window.

  • msg - The message to log

Function NewLogging( openModal As Long ) As Dword
Create a new logging window.

  • openModal - 1 to open the Logging window modally. You might do this if the logging window were the last one opened. 0 to open the logging window modelessly.