Modifying a GUI control from a different script

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Yelseppi
Posts: 3
Joined: 23 Dec 2022, 06:52

Modifying a GUI control from a different script

Post by Yelseppi » 29 Mar 2023, 10:30

Hi,

I have trawled the internet and the available docs but cant crack the code and am pulling my hair out. I'll be bald soon anyway, so help is needed to preserve what I have left.

I have a GUI set up via 'Gui, CleverGUI: Add' that enables me to run other AHK Scripts that I have available from a specific folder via buttons (rather than navigating to the directory each time I need to run them). When I run one of the scripts, I want a text field within the GUI to receive regular updates from the second script as it runs.

The AHK that creates the CleverGUI uses:

Code: Select all

Gui, CleverGUI: Add, Text, x5 y30 h35 w175 Center vTextMessage, No AHK scripts running
And I am trying to modify it from the second script using:

Code: Select all

GuiControl, CleverGUI: ,TextMessage, Now XXXX is running.
I also tried using Edit:

Code: Select all

Gui, CleverGUI: Add, Edit, R20 vMyEdit
And then modifying the Edit control from the second script using:

Code: Select all

GuiControl, CleverGUI: ,MyEdit, Now XXX is running
Neither of these work.

The following topics exist that come really close, but can't quite get me there: Please save me.

[Mod edit: Removed some wrongly applied indent tags, fixed some. They belong around some text and need an indentation level. Instead, added some [code][/code] tags.]

Yelseppi
Posts: 3
Joined: 23 Dec 2022, 06:52

Re: Modifying a GUI control from a different script

Post by Yelseppi » 29 Mar 2023, 11:12

On the offchance, I tried ChatGPT to help me and what do you know, it worked!

Here is the solution that I can take no credit for:

WinGet, hWnd, ID, CleverGUI
ControlSetText, % "Static1", INPUT AMENDMENT TO TEXT HERE, ahk_id %hWnd% ("Static 1" may vary depending on the order that the GUI controls were added. Windows Spy helped to get the correct one)
WinShow, ahk_id %hWnd%

It might help someone else in the future. This thread can be closed.

User avatar
mikeyww
Posts: 26972
Joined: 09 Sep 2014, 18:38

Re: Modifying a GUI control from a different script

Post by mikeyww » 29 Mar 2023, 11:16

Hi, in some cases, the :arrow: Control command works.

Post Reply

Return to “Ask for Help (v1)”