This code uses the built-in abilities of PureBasic and is cross-platform.
Code: Select all
Enumeration
#wndw
#imageid
#gadgetid
#gadgetct
EndEnumeration
lh=19 : bw=19
lnes=15
imageh=lnes*lh
w=200
h=200+bw
If OpenWindow(#wndw,0,0,w,h, "Which line?", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
If CreateImage(#imageid,w-bw,imageh)
If StartDrawing(ImageOutput(#imageid))
DrawingMode(#PB_2DDrawing_Transparent)
For lne=0 To lnes-1
If lne % 2
Box(0,lne*lh,w,lh,$99FF99)
Else
Box(0,lne*lh,w,lh,$FFFFFF)
EndIf
DrawText(xtab,(lne*lh)+yoffset,"Line "+Str(lne+1),0)
Next
StopDrawing()
EndIf
EndIf
ScrollAreaGadget(#gadgetct,0,0,w,h,w-bw,imageh,1)
ImageGadget(#gadgetid,0,0,w,imageh,ImageID(#imageid))
CloseGadgetList()
SetGadgetData(#gadgetid,lh) ; to carry over to event loop
EndIf
Repeat
Select WaitWindowEvent()
Case #PB_Event_Gadget
Select EventGadget()
Case #gadgetid,#gadgetct ; ScrollAreaGadget scrollbar doesn't give an event
id=((WindowMouseY(#wndw)+GetGadgetAttribute(#gadgetct,#PB_ScrollArea_Y ))/GetGadgetData(#gadgetid))
Debug "Line "+Str(id+1)
; Debug GetGadgetAttribute(#gadgetct,#PB_ScrollArea_Y )
; Debug GetGadgetAttribute(#gadgetct,#PB_ScrollArea_X )
; Debug GetGadgetAttribute(#gadgetct,#PB_ScrollArea_InnerHeight)
; Debug GetGadgetAttribute(#gadgetct,#PB_ScrollArea_InnerWidth)
EndSelect
Case #PB_Event_CloseWindow
Break ; End
EndSelect
ForEver