WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Boxes Functions
plus
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Awesome ListBox in Boxes Example.txt

Keywords:   ListBox Boxes 

Someone pointed out an example of using a list box in a WinBatch box. I liked the idea, so I added some extra code for others to play with. I had to modify this to remove some not yet available features, but it's just as functional here. The code even looks cleaner in some ways.
;Listbox, dependant listbox
Gosub Defines
Gosub SetupArray
AddExtender("WWCTL34I.DLL")

; Create parent box
BoxesUp("100,100,900,900", @NORMAL)
BoxButtonDraw(1, 1, "OK", "550,950,450,900")
BoxButtonDraw(1, 2, "Cancel", "750,950,650,900")

; Set up API call arguments
dwExStyle = nWSxEXxCLIENTEDGE
lpClassName = "ListBox"
lpWindowName = 0

dwStyle = nWSxCHILD | nWSxTABSTOP | nWSxVISIBLE | nWSxVSCROLL
dwStyle = dwStyle | nLBSxUSETABSTOPS |nWSxGROUP

x = 10 ; pixels from left of parent window
y = 10 ; pixesl from top of parent window

; My display resolution is 1600x1200;
; GetClientRect can be used to relate pixels to BoxesUp units
nWidth = 300 ; pixels
nHeight = 200 ; pixels

hWndParent = DLLhWnd("")
hInstance = DLLhInst("")
lParam = 0

hMenu = 3
Gosub CreateListBox
ListBox1 = hWndList
; Add items to ListBox
Gosub Fill1stListBox
; Highlight one of the items
cSetLBItemEx(hWndList, 1)

hMenu = 4
x = 310 ; pixels from left of parent window
y = 10 ; pixesl from top of parent window

; My display resolution is 1600x1200;
; GetClientRect can be used to relate pixels to BoxesUp units
nWidth = 300 ; pixels
nHeight = 200 ; pixels

Gosub CreateListBox
ListBox2 = hWndList

itemChosen = 1
Gosub Fill2ndListBox

; Wait for the user to hit a button
LastItemChosen = 1
ItemChosen = 1
While @TRUE
TimeDelay(0.1)
If BoxButtonStat(1, 1) Then Break
If BoxButtonStat(1, 2) Then Break
sChosen = cGetLBSelText(ListBox1)
sChosen = ItemExtract(1, sChosen, @TAB)
for loop = 1 to Item0Count
If sChosen == ItemExtract(loop, item0, @TAB)
itemChosen = loop
EndIf
next loop

if LastItemChosen != itemChosen
Gosub Fill2ndListBox
LastItemChosen = ItemChosen
endif
EndWhile

BoxDestroy(1)
EXIT


;***************************
:Fill1stListBox
;***************************
IntControl(22, ListBox1, LBxRESETCONTENT, 0, 0)
for loop = 1 to Item0Count
sText = itemExtract(loop, item0, @TAB)
IntControl(22, ListBox1, nLBxADDSTRING, 0, sText)
next loop
RETURN



;***************************
:Fill2ndListBox
;***************************
IntControl(22, ListBox2, LBxRESETCONTENT, 0, 0)
for loop = 1 to Item%itemChosen%Count
sText = itemExtract(loop, item%ItemChosen%, @TAB)
IntControl(22, ListBox2, nLBxADDSTRING, 0, sText)
next loop
RETURN
;;;#DefineFunction FillListBox2(hwnd, Array, 
;------------------------------------------------------------


;***************************
:SetupArray
;***************************
item0 = StrCat("Marty", @TAB, "Don", @TAB, "Bill", @TAB, "Linus")
item1 = StrCat("Marty - ONE", @TAB, "Marty - TWO", @TAB, "Marty - THREE")
item2 = StrCat("Don - ONE", @TAB, "Don - TWO", @TAB, "Don - THREE", @TAB, "Don - Four")
item3 = "Bill - Only"
item4 = StrCat("Linus - ONE", @TAB, "Linus - TWO")
item0Count = ItemCount(item0, @TAB)
item1Count = ItemCount(item1, @TAB)
item2Count = ItemCount(item2, @TAB)
item3Count = ItemCount(item3, @TAB)
item4Count = ItemCount(item4, @TAB)
RETURN

;***************************
:CreateListBox
;***************************
; Create the ListBox
sDLLName = StrCat(DirWindows(1), "User32.DLL")
sEntry = StrCat("long:", '"CreateWindowExA"')

sArgs = "long:dwExStyle"
sArgs = StrCat(sArgs, ", lpstr:lpClassName")
sArgs = StrCat(sArgs, ", long:lpWindowName")
sArgs = StrCat(sArgs, ", long:dwStyle")
sArgs = StrCat(sArgs, ", long:x")
sArgs = StrCat(sArgs, ", long:y")
sArgs = StrCat(sArgs, ", long:nWidth")
sArgs = StrCat(sArgs, ", long:nHeight")
sArgs = StrCat(sArgs, ", long:hWndParent")
sArgs = StrCat(sArgs, ", long:hMenu")
sArgs = StrCat(sArgs, ", long:hInstance")
sArgs = StrCat(sArgs, ", long:lParam")

hWndList = DLLCall(sDLLName, %sEntry%, %sArgs%)
RETURN
;-----------------------------------------------------


;**************
:Defines
;**************
; Define standard window style constants
nWSxCHILD = 16384 << 16
nWSxGROUP = 2 << 16
nWSxTABSTOP = 1 << 16
nWSxVISIBLE = 4096 << 16
nWSxVSCROLL = 32 << 16

; Define ListBox window style constants
nLBSxUSETABSTOPS = 128

; Define extended window style constants
nWSxEXxCLIENTEDGE = 512

; Define Win32 message constants
nLBxADDSTRING = 384
LBxRESETCONTENT = 388 ;H184

RETURN
;-----------------------------------------------------

Article ID:   W14828
File Created: 2001:11:08:12:40:12
Last Updated: 2001:11:08:12:40:12