How to write to this gui text control Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
AHKStudent
Posts: 1472
Joined: 05 May 2018, 12:23

How to write to this gui text control

21 Sep 2021, 03:21

Using Static1 is not an option so I am trying to use the hwnd of the control, I tried even the most ridiculous combinations

Code: Select all

#NoEnv
#SingleInstance Force
SetWorkingDir %A_ScriptDir%

Gui Add, Text, x79 y13 w275 h23 +0x200 hwndF1, 
Gui Add, Button, x177 y83 w80 h23 gworks, Works
Gui Add, Button, x177 y110 w80 h23 gnowork, Doesn't work

Gui Show, w453 h212, Window
Return

works:
ControlSetText,,Hello, ahk_id %F1%
return

nowork:
loop, 1
{
	field = F%a_index%
	field2 := "F" a_index
	MsgBox, % field "`n" field2
	ControlSetText,,NoWork, ahk_id F%a_index%
	ControlSetText,,NoWork, ahk_id F %a_index%
	ControlSetText,,NoWork, ahk_id "F" %a_index%
	ControlSetText,,NoWork, ahk_id "F" a_index
	ControlSetText,,NoWork, ahk_id %field%
	ControlSetText,,NoWork, ahk_id %field2%
	ControlSetText,,NoWork, ahk_id %F%%a_index%
	ControlSetText,,NoWork, ahk_id %Fa_index%

}
return

GuiEscape:
GuiClose:
    ExitApp
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: How to write to this gui text control  Topic is solved

21 Sep 2021, 03:31

for manipulating AHK controls use GuiControl/Get

Code: Select all

GuiControl, , % F1, the text or whatever
just me
Posts: 9442
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: How to write to this gui text control

21 Sep 2021, 03:34

Code: Select all

#NoEnv
#SingleInstance Force
SetWorkingDir %A_ScriptDir%

Gui Add, Text, x79 y13 w275 h23 +0x200 hwndF1,
Gui Add, Button, x177 y83 w80 h23 gworks, Works
Gui Add, Button, x177 y110 w80 h23 gnowork, Doesn't work

Gui Show, w453 h212, Window
Return

works:
; ControlSetText,,Works, ahk_id %F1%
GuiControl, , %F1%, Works
return

nowork:
I := 1
; ControlSetText,,Doesn't work, % "ahk_id " . F%I%
GuiControl, , % F%I%,  Doesn't work
return
AHKStudent
Posts: 1472
Joined: 05 May 2018, 12:23

Re: How to write to this gui text control

21 Sep 2021, 03:42

can't believe how much time I spent on this, thank you both
garry
Posts: 3758
Joined: 22 Dec 2013, 12:50

Re: How to write to this gui text control

21 Sep 2021, 14:28

I was playing with Controlsettext / Guicontrol / hwndF1 / vF1 ( to see the difference )
Example-1 with hwndF1

Code: Select all

#NoEnv
#SingleInstance Force
SetWorkingDir %A_ScriptDir%
Gui,2: Add, Text, x79 y13 w275 h23 +0x200 hwndF1 ,
Gui,2: Add, Button, x177 y83  w80 h23 gA1, Example-1
Gui,2: Add, Button, x177 y110 w80 h23 gA2, Example-2
Gui,2: Show, w453 h212, Window
Return
;--------------------------
2Guiclose:
exitapp
;--------------------------
A1:
GuiControl,2: , %F1%, Works A1
return
;--------------------------
A2:
I := 1
aa:="ahk_id " .  F%I%
ControlSetText,,Works A2-a,%aa%                  ;- OK
sleep,2000
ControlSetText,,Works A2-b, % "ahk_id " . F1     ; -OK
sleep,2000
GuiControl,2: , % F%I%, Works A2-c               ;- OK
sleep,2000
GuiControl,2: ,%F1%, A2-ENDED                  ;- OK
return
;==========================
Example-2 with variable vF1

Code: Select all

#NoEnv
#SingleInstance Force
SetWorkingDir %A_ScriptDir%
Gui,2: Add, Text, x79 y13 w275 h23    vF1 ,
Gui,2: Add, Button, x177 y83  w80 h23 gA1, Example-1
Gui,2: Add, Button, x177 y110 w80 h23 gA2, Example-2
Gui,2: Show, w453 h212, Window
Return
;--------------------------
2Guiclose:
exitapp
;--------------------------
A1:
GuiControl,2: ,F1, Works A1
return
;--------------------------
A2:
I := 1
aa:=F%I%
ControlSetText,,Works A2-a,%F1%       ;- OK
sleep,2000
ControlSetText,,Works A2-b,%aa%       ; -OK
sleep,2000
GuiControl,2: , F%I%, Works A2-c      ;- OK
sleep,2000
GuiControl,2: ,F1, A2-ENDED         ;- OK
return
;==========================

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot], ReyAHK, Spawnova and 287 guests