Page 1 of 1

How to write to this gui text control

Posted: 21 Sep 2021, 03:21
by AHKStudent
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

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

Posted: 21 Sep 2021, 03:31
by swagfag
for manipulating AHK controls use GuiControl/Get

Code: Select all

GuiControl, , % F1, the text or whatever

Re: How to write to this gui text control

Posted: 21 Sep 2021, 03:34
by just me

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

Re: How to write to this gui text control

Posted: 21 Sep 2021, 03:42
by AHKStudent
can't believe how much time I spent on this, thank you both

Re: How to write to this gui text control

Posted: 21 Sep 2021, 14:28
by garry
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
;==========================