del
New Member
Posts: 12
|
Post by del on Apr 3, 2024 8:48:42 GMT -5
Point of Interest: Has anyone here ever suggested the inclusion of Control Arrays in Liberty Basic. e.g. Button #win.Press(n), "Press" + Str$(n), SubButtArraySetup, UL, x, y, w, h
|
|
|
Post by tsh73 on Apr 3, 2024 10:00:52 GMT -5
Is there any particular use you have in mind?
Because LB already offers something along that. Are you know one could use variable handles for controls in LB? This way you can control several buttons with same code And use same handler sub (the only thing you cannot do easily - is to CREATE controls in a loop)
'button handler demo
' Form created with the help of Freeform-J v.261006 ' Generated on Apr 03, 2024 at 17:48:13
nomainwin
WindowWidth = 550 WindowHeight = 410
UpperLeftX=int((DisplayWidth-WindowWidth)/2) UpperLeftY=int((DisplayHeight-WindowHeight)/2)
button #main.button1, "setup buttons", [button1Click], UL, 26, 16, 122, 25 'buttons to be used as array - with consequent handles, here #main.btN button #main.bt1, "Button Caption", btClick, UL, 70, 56, 122, 25 button #main.bt2, "Button Caption", btClick, UL, 214, 56, 122, 25 button #main.bt3, "Button Caption", btClick, UL, 366, 56, 122, 25 texteditor #main.log, 38, 131, 456, 215 statictext #main.statictext6, "click this button ", 158, 21, 144, 20 statictext #main.statictext7, "now use buttons above", 38, 96, 144, 20
open "Control handle demo" for window as #main print #main, "trapclose [quit.main]"
print #main, "font ms_sans_serif 10"
wait
[quit.main] Close #main END
[button1Click] 'Perform action for the button named 'button1' 'setup buttons - use them as array (by index) for i = 1 to 3 'index 'make a handle by index handle$="#main.bt";i 'use button by handle #handle$ word$("Veni Vidi Vici", i) next #main.log "Buttons are renamed" wait
sub btClick handle$ #main.log "You clicked button ";handle$ 'get index back from handle i = val(right$(handle$,1)) #main.log "That supposed to be "; word$("Veni Vidi Vici", i) end sub
|
|
del
New Member
Posts: 12
|
Post by del on Apr 4, 2024 11:34:23 GMT -5
Thanks for that code example, it help me out a lot, I was trying to avoid creating 31 subroutines one for each button, now I can condense it down to one. Never seen that before, did not know you could use variable handles for controls. I'll still have to put up with the 31 lines to create a grid of buttons, but that's not so bad.
|
|
|
Post by Rod on Apr 4, 2024 14:13:08 GMT -5
BASIC isn’t Windows so you don’t even need to use “controls” you can use a graphicbox.
Tell us a little bit more about your button interface.
|
|
|
Post by metro on Apr 4, 2024 22:03:44 GMT -5
Unsure if this is of any use I created it to use with an invoicing program so I didn't have to type in line item descriptions the button text is copied to clipboard, then I pasted it into MYOB line items.
Rod has gifted us several graphic examples over the years too
nomainwin ' Dynamic Buttons Demo ' By Brent D. Thorn, 2006 ' PUBLIC DOMAIN DIM caption$(25) caption$(1)="5 Yearly Termite Barrier to home using ";chr$(34);"IMIDACLOPRID";chr$(34) caption$(2)="5 Yearly Termite Barrier to home using ";chr$(34);"FIPRONIL";chr$(34) caption$(4)="5 Yearly Termite Barrier to home using ";chr$(34);"BIFLEX";chr$(34) caption$(3)="5 Yearly Termite Barrier to home using ";chr$(34);"BIFENTHRIN";chr$(34) caption$(5)="Termite Treated Zone to Home using ";chr$(34);"IMIDACLOPRID";chr$(34) caption$(6)="Termite Treated Zone to Home using ";chr$(34);"FIPRONIL";chr$(34) caption$(8)="Termite Treated Zone to Home using ";chr$(34);"BIFLEX";chr$(34) caption$(7)="Termite Treated Zone to Home using ";chr$(34);"BIFENTHRIN";chr$(34) caption$(9)="Annual Inspection for Extended Warranty" caption$(10)="Treatment for Ant Infestation" caption$(11)="Treatment for Spiders" caption$(12)="General Pest Treatment" caption$(13)="Supply & Install Below Ground Alway Active Bait Stations" caption$(14)="Spot Treatment of Active Termites" caption$(15)="Supply & Install Rodent Baiting System" caption$(16)="End of lease flea treatment" caption$(17)="5 Yearly Termite Barrier using TERMIDOR" caption$(19)="Treatment for Ant & Spiders" caption$(20)="Supply & Install Below Ground Alway Active Bait Stations" caption$(21)="Spot Treatment of Active Termites" caption$(22)="Supply & Install Rodent Baiting Boxes" caption$(23)= "Annual Inspection for Extended Warranty" caption$(18)="Pre-Purchase Timber Pest Inspection" caption$(24)="FOOTER"
' open "footer.txt" for input as #g ' footer$= input$(#g, lof(#g)) ' CLOSE #g '============================================== 'footer$= " A long blurb" ' JUST FOR TESTING '==============================================
Global g.hInstance,footer$,caption$, hMemory,hwndOwner Global g.nButtons
CallDLL #kernel32, "GetModuleHandleA", _ _NULL As ULong, _ g.hInstance As ULong
g.nButtons = 24
Dim hwndButtons(g.nButtons)
Open "WMLiberty" For DLL As #wmlib
WindowWidth=440:WindowHeight=490 UpperLeftX=int((DisplayWidth-WindowWidth)-30) UpperLeftY= 60 ' int((WindowHeight-1320)) StaticText #demo.stc,"",4,4,300,20
Open "Service Descriptions" For Dialog As #demo
#demo "TrapClose demo.Close"
hWnd = HWnd(#demo) Callback lpfn, OnCommand(ULong,ULong,ULong,ULong),Long
CallDLL #wmlib, "SetWMHandler", _ hWnd As ULong, _ _WM_COMMAND As ULong, _ lpfn As ULong, _ -1 As Long, _ ret As Long
CallDLL #gdi32, "GetStockObject", _ _DEFAULT_GUI_FONT As Long, _ hFont As ULong dwStyle = _WS_CHILD Or _WS_VISIBLE Or _BS_PUSHBUTTON or _BS_CENTER or _BS_MULTILINE nWidth = Int((WindowWidth-16) / 4) nHeight = 67 x = 4 y = 35
For b = 1 To g.nButtons hwndButtons(b) = _ CreateWindowEx(0, "BUTTON", caption$(b), _ dwStyle, x, y, nWidth, nHeight, _ hWnd, 0, g.hInstance, 0) Call SendMessageLong hwndButtons(b), _WM_SETFONT, hFont, 1 x = x + nWidth If x+nWidth > WindowWidth Then x = 4 y = y + nHeight End If
Next Call DoEvents WAIT
Sub DoEvents [localLoop] Scan CallDLL #kernel32, "Sleep", 50 As Long, ret As Void GoTo [localLoop] End Sub
Sub demo.Close me$ CALL EMPTY.CLIP Close #me$ Close #wmlib END CLOSE #demo End Sub
SUB EMPTY.CLIP CALLDll #user32, "OpenClipboard",_ hWnd as long,_ 'window handle or 0 r as boolean
CALLDll #user32, "EmptyClipboard", r as boolean CallDll #kernel32, "GlobalFree", hMemory as ulong, GlobalFree as long CALLDll #user32, "CloseClipboard", r as boolean END SUB
Function OnCommand( hWnd, uMsg, wParam, lParam )
Select Case HIWORD(wParam) Case _BN_CLICKED For b = 1 To g.nButtons
If hwndButtons(b) = lParam Then Exit For Next If b <= g.nButtons Then SELECT CASE b ' CASE ( b< 24) CASE 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23 #demo.stc caption$(b);"." r= CopyText(caption$(b)+Chr$(32)) CASE 24 #demo.stc caption$(b);"." r= CopyText(footer$+Chr$(32)) END SELECT End If End Select
'====================================================== ' print lParam;" ";b;" ";caption$(b) 'FOR TESTING '====================================================== End Function
Function CreateWindowEx( StyleEx, Class$, Text$, Style, X, Y, Width, Height, Parent, ID, Instance, Param ) CallDLL #user32, "CreateWindowExA", _ StyleEx As ULong, Class$ As Ptr, Text$ As Ptr, Style As ULong, _ X As Long, Y As Long, Width As ULong, Height As ULong, _ Parent As ULong, ID As ULong, Instance As ULong, _ Param As ULong, CreateWindowEx As ULong End Function
Sub SendMessageLong hWnd, uMsg, wParam, lParam CallDLL #user32, "SendMessageA", _ hWnd As ULong, uMsg As ULong, _ wParam As ULong, lParam As ULong, _ ret As Long End Sub
Function HIWORD( dw ) HIWORD = (dw And 4294901760) / 65536 End Function
Function LOWORD( dw ) LOWORD = (dw And 65535) End Function
function changeStyle(h,ms) calldll #user32,"GetWindowLongA",h as long,_ _GWL_STYLE as long,style as long style=style or ms calldll #user32,"SetWindowLongA",_ h as long,_GWL_STYLE as long,style as long, _ changeStyle as long end function
[fin1] Close #me$ Close #wmlib END
FUNCTION CopyText(Text$) Size = Len(Text$) 'allocate a block of memory the size of the text: CALLDll #kernel32, "GlobalAlloc",_ _GMEM_MOVEABLE as long,_ 'type Size as ulong,_ 'size of memory block to allocate hMemory as long 'handle to memory 'lock the memory block CALLDll #kernel32, "GlobalLock",_ hMemory as long,_ 'handle of memory lpMemory as long 'pointer to locked memory 'copy the text into locked memory CALLDll #kernel32,"RtlMoveMemory",_ lpMemory as ulong,_ 'pointer to locked memory Text$ as ptr,_ 'text to copy to memory Size as long,_ 'length of text to copy ret as void 'unlock memory CALLDll #kernel32, "GlobalUnlock",_ hMemory as long,_ 'handle to memory ret as long 'open the clipboard CALLDll #user32, "OpenClipboard",_ hwndOwner as long,_ 'window handle or 0 r as boolean 'clear clipboard CALLDll #user32, "EmptyClipboard", ret as boolean 'copy text string to the clipboard CALLDll #user32, "SetClipboardData", _CF_TEXT as long,_ 'type of data hMemory as long,_ 'handle to memory block CopyText as long 'nonzero = success 'CLOSE the clipboard CALLDll #user32, "CloseClipboard", r as boolean 'if the attempt to set data to the clipboard 'failed, it is necessary to free the memory IF CopyText = 0 THEN CALLDll #kernel32, "GlobalFree", hMemory as ulong, ret as long 'handle to memory NOTICE "FAILED" END IF END FUNCTION
|
|