I have 2 StringGadgets and I want to be able select the contents of one StringGadget or the other with my mouse and then determine which StringGadget has it’s text selected. Is this possible?
I have a button that populates the StringGadgets when pressed. I can’t use GetActiveGadget() because it shows the active gadget is the button. If I click in one of the StringGadgets and use GetActiveGadget() it still shows the active gadget as the button. I can’t use SetActiveGadget() because it could be either of the two that I want the text from.
Find which StringGadget has it’s text selected
Find which StringGadget has it’s text selected
http://www.oldtimeradiotoday.com - Listen to or download classic old time radio broadcasts.
Re: Find which StringGadget has it’s text selected
With the Little John's help.
Code: Select all
; Little John: http://www.purebasic.fr/english/viewtopic.php?p=375082#p375082
Define start.i, stop.i
OpenWindow(0, 0, 0, 322, 205, "StringGadget", #PB_Window_MinimizeGadget | #PB_Window_ScreenCentered)
StringGadget(1, 8, 10, 306, 20, "Bla Blib Blub")
StringGadget(2, 8, 40, 306, 20, "abc def")
Repeat
Select WaitWindowEvent()
Case #WM_LBUTTONUP ; Mouse up
If GetActiveWindow() = 0 And GetActiveGadget() = 1
SendMessage_(GadgetID(1), #EM_GETSEL, @start, @stop) ; get selected text
Debug "'" + Mid(GetGadgetText(1), start + 1, stop - start) + "'"
EndIf
If GetActiveWindow() = 0 And GetActiveGadget() = 2
SendMessage_(GadgetID(2), #EM_GETSEL, @start, @stop) ; get selected text
Debug "'" + Mid(GetGadgetText(2), start + 1, stop - start) + "'"
EndIf
Case #PB_Event_CloseWindow
Break
EndSelect
ForEver

Re: Find which StringGadget has it’s text selected
Thank you so much eJan. It works perfectly!
Cheers and stay safe!
Cheers and stay safe!
http://www.oldtimeradiotoday.com - Listen to or download classic old time radio broadcasts.