'============================================================================== ' ' List Box encapsulation for PB/DLL 5.0 ' Copyright (c) 1997 by PowerBASIC, Inc. ' ' Note: Assumes that WIN32API.INC will also be included into your code. ' '============================================================================== '------------------------------------------------------------------------------ ' TITLE: LbAddFile ' DESC: Add a specified filename to a list box that contains a directory ' listing. ' SYNTAX: RetVal = LbAddFile(hListBox, Filename$) ' PARAM: hListBox - Handle of the list box. ' Filename$ - Filename to add to the list box. 'RETURNS: The return value is the zero-based index to the filename in the list ' box. The return value is %LB_ERR if an error occurs; the return value ' is %LB_ERRSPACE if insufficient space is available to store the new ' filename. 'REMARKS: The list box to which Filename$ is added must have been filled by ' the LbDir call. ' FUNCTION LbAddFile(BYVAL hListBox AS LONG, BYVAL Filename AS STRING) AS LONG FUNCTION = SendMessage(hListBox, %LB_ADDFILE, 0, STRPTR(Filename)) END FUNCTION '------------------------------------------------------------------------------ ' TITLE: LbAddString ' DESC: Add a string to a list box. ' SYNTAX: RetVal = LbAddString(hListBox, Text$) ' PARAM: hListBox - Handle of the list box. ' Text$ - Text string to add to the list box. 'RETURNS: The return value is the zero-based index to the string in the list ' box. The return value is %LB_ERR if an error occurs; the return value ' is %LB_ERRSPACE if insufficient space is available to store the new ' string. 'REMARKS: If the list box does not have the %LBS_SORT style, the string is ' added to the end of the list. Otherwise, the string is inserted ' into the list and the list is sorted. ' FUNCTION LbAddString(BYVAL hListBox AS LONG, BYVAL Text AS STRING) AS LONG FUNCTION = SendMessage(hListBox, %LB_ADDSTRING, 0, STRPTR(Text)) END FUNCTION '------------------------------------------------------------------------------ ' TITLE: LbDeleteString ' DESC: Delete a string from a list box. ' SYNTAX: RetVal = LbDeleteString(hListBox, Position) ' PARAM: hListBox - Handle of the list box. ' Position - Zero based index of the string to delete in the list box. 'RETURNS: The return value is a count of the strings remaining in the list. ' The return value is %LB_ERR if the index parameter specifies an index ' greater than the number of items in the list. ' FUNCTION LbDeleteString(BYVAL hListBox AS LONG, BYVAL Index AS LONG) AS LONG FUNCTION = SendMessage(hListBox, %LB_DELETESTRING, Index, 0) END FUNCTION '------------------------------------------------------------------------------ ' TITLE: LbDir ' DESC: Fill the list box with a file directory. ' SYNTAX: RetVal = LbDir(hListBox, FileAttribute, FileSpec$) ' FUNCTION LbDir(BYVAL hListBox AS LONG, BYVAL Attr AS LONG, _ BYVAL FileSpec AS STRING) AS LONG FUNCTION = SendMessage(hListBox, %LB_DIR, Attr, STRPTR(FileSpec)) END FUNCTION '------------------------------------------------------------------------------ ' TITLE: LbGetCount ' DESC: Return the total number of items in a list box. ' SYNTAX: n = LbGetCount( hListBox ) ' FUNCTION LbGetCount(BYVAL hListBox AS LONG) AS LONG FUNCTION = SendMessage(hListBox, %LB_GETCOUNT, 0, 0) END FUNCTION '------------------------------------------------------------------------------ ' TITLE: LbGetCurSel ' DESC: Get the current selection index of the list box. ' SYNTAX: ItemPosition = LbGetCurSel( hListBox ) ' FUNCTION LbGetCurSel(BYVAL hListBox AS LONG) AS LONG FUNCTION = SendMessage(hListBox, %LB_GETCURSEL, 0, 0) END FUNCTION '------------------------------------------------------------------------------ ' TITLE: LbGetSel ' DESC: Returns the select status of the specified item. ' SYNTAX: Status = LbGetSel hListBox, ItemPosition ) ' FUNCTION LbGetSel(BYVAL hListBox AS LONG, BYVAL Index AS LONG) AS LONG FUNCTION = (SendMessage(hListBox, %LB_GETSEL, Index, 0) <> 0) END FUNCTION '------------------------------------------------------------------------------ ' TITLE: LbGetText ' DESC: Return the text of the selected list box item. ' SYNTAX: Text$ = LbGetText( hListBox, ItemPosition ) ' FUNCTION LbGetText(BYVAL hListBox AS LONG, BYVAL Index AS LONG) AS STRING LOCAL Buffer AS ASCIIZ * 256 IF Index < 0 THEN Index = LbGetSelect(hListBox) END IF SendMessage hListBox, %LB_GETTEXT, Index, VARPTR(Buffer) FUNCTION = Buffer END FUNCTION '------------------------------------------------------------------------------ ' TITLE: LbInsertString ' DESC: Insert a string into a list box. ' SYNTAX: RetVal = LbInsertString(hListBox, Position, Text$) ' PARAM: hListBox ' Position ' Text$ 'RETURNS: The return value is the index of the position at which the string was ' inserted. The return value is %LB_ERR if an error occurs. The return ' value is %LB_ERRSPACE if insufficient space is available to store the ' new string. 'REMARKS: Unlike LbAddString, LbInsertString does not cause a list with the ' %LBS_SORT style to be sorted. ' FUNCTION LbInsertString(BYVAL hListBox AS LONG, BYVAL Index AS LONG, _ BYVAL Text AS STRING) AS LONG FUNCTION = SendMessage(hListBox, %LB_INSERTSTRING, Index, STRPTR(Text)) END FUNCTION '------------------------------------------------------------------------------ ' TITLE: LbResetContent ' DESC: Clear the contents of a list box. ' SYNTAX: LbResetContent hListBox ' SUB LbResetContent(BYVAL hListBox AS LONG) SendMessage hListBox, %LB_RESETCONTENT, 0, 0 END SUB '------------------------------------------------------------------------------ ' TITLE: LbSelectString ' DESC: Select an item in a list box by its text (or partial text). ' SYNTAX: RetVal = LbSelectString(hListBox, StartPosition, Text$) 'REMARKS: The return value is the index of the selected item if the search was ' successful. The return value is %LB_ERR if the search was ' unsuccessful and the current selection is not changed. ' FUNCTION LbSelectString(BYVAL hListBox AS LONG, BYVAL Start AS LONG, _ BYVAL Text AS STRING) AS LONG FUNCTION = SendMessage(hListBox, %LB_SELECTSTRING, Start, STRPTR(Text)) END FUNCTION '------------------------------------------------------------------------------ ' TITLE: LbSetCurSel ' DESC: Set the highlighted item in a list box. ' SYNTAX: RetVal = LbSetCurSel(hListBox, ItemPosition) ' PARAM: hListBox ' ItemPosition 'RETURNS: The return value is %LB_ERR if an error occurs. The return value ' will be %LB_ERR even though no error has occurred if the index ' parameter is -1. 'REMARKS: LbSetCurSel selects a string and scrolls it into view, if necessary. ' When the new string is selected, the list box removes the highlight ' from the previously selected string. If the index parameter is -1, ' the list box is set to have no selection. ' FUNCTION LbSetCurSel(BYVAL hListBox AS LONG, BYVAL Index AS LONG) AS LONG FUNCTION = SendMessage(hListBox, %LB_SETCURSEL, Index, 0) END FUNCTION '------------------------------------------------------------------------------ ' TITLE: LbSetTabStops ' DESC: Set the tab stops in a list box. ' SYNTAX: LbSetTabStops hListBox, TabStops(0), TotalTabStops 'REMARKS: TabStops() is a long integer array with each succeeding tab stop ' greater than the previous. The listbox must have been created with ' the %LB_USETABSTOPS style. ' SUB LbSetTabStops(BYVA: hListBox AS LONG, TabStops AS LONG, _ BYVAL TabStopsCnt AS LONG) SendMessage hListBox, %LB_SETTABSTOPS, TabStopsCnt, VARPTR(TabStops) END SUB