|
Post by angelo2449 on Oct 30, 2022 9:57:44 GMT -5
Hi guys,
has anyone written any code to read the contents of a button?
Thank you all.
|
|
honky
Junior Member
Posts: 62
|
Post by honky on Oct 30, 2022 10:10:03 GMT -5
a$="Yess" BUTTON #w.n1, a$, [yess], UL, 120, 20, 40, 20 Button content is dans a$ But button name cannot be changed
|
|
|
Post by tsh73 on Oct 30, 2022 12:44:56 GMT -5
Yes it is possible by calling Windows API (Go Links / Static Copy of Liberty BASIC Programmer's Encyclopedia / Windows API / ABC of API if you want to understand how it works.)
But since is it you who give the button caption, storing that text in a variable is easier option.
'Form created with the help of Freeform 3 v07-31-2015 'Generated on Oct 30, 2022 at 20:32:22
[setup.main.Window]
'-----Begin code for #main
nomainwin WindowWidth = 515 WindowHeight = 135 UpperLeftX=int((DisplayWidth-WindowWidth)/2) UpperLeftY=int((DisplayHeight-WindowHeight)/2)
'-----Begin GUI objects code
groupbox #main.groupbox1, "button with caption to chenge/read", 15, 17, 240, 75 button #main.button2,"Silly Caption",[button2Click], UL, 30, 42, 120, 35 TextboxColor$ = "white" textbox #main.textbox3, 270, 17, 100, 25 button #main.button4,"Set Caption",[button4Click], UL, 390, 17, 100, 25 button #main.button5,"Get Caption",[button5Click], UL, 390, 57, 100, 25
'-----End GUI objects code
open "getting windows text" for window as #main print #main, "font ms_sans_serif 10" print #main, "trapclose [quit.main]" #main.textbox3 "New Caption"
[main.inputLoop] 'wait here for input event wait
[button2Click] 'Perform action for the button named 'button2'
'Insert your own code here
wait
[button4Click] 'Perform action for the button named 'button4' #main.textbox3 "!contents? newCapption$" #main.button2, newCapption$ wait
[button5Click] 'Perform action for the button named 'button5' caption$=space$(128) length=len(caption$)+1 h=hwnd(#main.button2) calldll #user32, "GetWindowTextA", _ h as ulong, _ caption$ as ptr, _ length as long, _ res as long
'notice "res ";res 'should be not 0. Actually returns length of the caption
caption$ = trim$(caption$) notice "The button caption is"+chr$(13)+caption$
wait
[quit.main] 'End the program close #main end
|
|
|
Post by Walt Decker on Oct 30, 2022 15:13:19 GMT -5
BtnHndl = HWND(#WIN.BTN)
CALLDLL #user32, "GetWindowTextLengthA", BtnHndl AS ULONG, NumChrs AS LONG
BtnCap$ = SPACE$(NumChrs)
CALLDLL #user32, "GetWindowTextA", BtnHndl AS ULONG, BtnCap$ AS STRUCT, NumChrs AS LONG, RetVal AS LONG
BtnCap$ = LEFT$(BtnCap$, RetVal)
BtnCap$ = "BUTTON NO NAME"
CALLDLL #user32, "SetWindowTextA", BtnHndl AS ULONG, BtnCap$ AS PTR, RetVal AS VOID
|
|