Changing Gui example to use named Gui

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
fade2gray
Posts: 85
Joined: 21 Apr 2015, 12:28

Changing Gui example to use named Gui

27 Aug 2023, 11:39

I'm having a tough time trying to convert a not so simple v1 Gui to v2, so I thought I'd go back to basics and compare a v1 documentation example with the same in the v2 documentation.

In the v2 #4 example, MyGui is used as the name. I tried doing the same with the v1 #4 example, but the OK button no longer functions.

Code: Select all

Gui, MyGui:Add, Text,, Pick a file to launch from the list below.`nTo cancel, press ESCAPE or close this window.
Gui, MyGui:Add, ListBox, vMyListBox gMyListBox w640 r10
Gui, MyGui:Add, Button, Default, OK
Loop, C:\Users\fade2gray\CheatEngine\CEC-v2\*.ahk  ; Change this folder and wildcard pattern to suit your preferences.
{
    GuiControl, MyGui:, MyListBox, %A_LoopFileFullPath%
}
Gui, MyGui:Show
return

MyListBox:
if (A_GuiEvent != "DoubleClick")
    return
; Otherwise, the user double-clicked a list item, so treat that the same as pressing OK.
; So fall through to the next label.
ButtonOK:
GuiControlGet, MyListBox,  ; Retrieve the ListBox's current selection.
MsgBox, 4,, Would you like to launch the file or document below?`n`n%MyListBox%
IfMsgBox, No
    return
; Otherwise, try to launch it:
Run, %MyListBox%,, UseErrorLevel
if (ErrorLevel = "ERROR")
    MsgBox Could not launch the specified file. Perhaps it is not associated with anything.
return

GuiClose:
GuiEscape:
ExitApp
User avatar
mikeyww
Posts: 27372
Joined: 09 Sep 2014, 18:38

Re: Changing Gui example to use named Gui

27 Aug 2023, 11:53

Hello,

This sounds like a question about a v2 script that you have not posted. Therefore, my suggestions are to use the v2 forum and to post your v2 script there. Include a description of what your script does, and what it should do instead.
User avatar
fade2gray
Posts: 85
Joined: 21 Apr 2015, 12:28

Re: Changing Gui example to use named Gui

27 Aug 2023, 12:14

Hi mikey,

Ok, before I go dumping 2,570 messy and unoptimised lines of code and asking for help with conversion, could you explain where I've gone wrong in my attempt to name the Gui in the above example?
User avatar
mikeyww
Posts: 27372
Joined: 09 Sep 2014, 18:38

Re: Changing Gui example to use named Gui

27 Aug 2023, 12:26

Certainly. Answer here: https://www.autohotkey.com/docs/v1/lib/Gui.htm#Labels
For windows other than number 1, the window's name or number (if it has one) is used as a prefix for the special labels mentioned above; for example, 2GuiEscape and 2GuiClose would be the default labels for window number 2, while MyGuiGuiEscape and MyGuiGuiClose would be the default labels for MyGui. To set a custom prefix, use Gui +Label.
User avatar
fade2gray
Posts: 85
Joined: 21 Apr 2015, 12:28

Re: Changing Gui example to use named Gui

27 Aug 2023, 12:50

Right, understood, thank you mikey.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Bing [Bot], Google [Bot], Marium0505, mcl and 345 guests