Create own class id for ahk gui?

Get help with using AutoHotkey and its commands and hotkeys
User avatar
Scr1pter
Posts: 429
Joined: 06 Aug 2017, 08:21
Location: Germany

Create own class id for ahk gui?

Post by Scr1pter » 21 Jul 2018, 18:07

Hi,

I found this 12 year old thread were someone had the same question:
https://autohotkey.com/board/topic/1091 ... ahk-class/

When I compile a script (e.g. one which creates an AHK gui), the class id is always:
ahk_class AutoHotkeyGUI

Is there a newer way to change the class id rather than using any hex tools?
I create guis for different applications.
If all guis have the same class id, there might be some problems.
because I often work with #if WinActive("ahk_class ...")

Regards
I'm not an expert, just an enthusiastic AutoHotkey user. 8-)
Please do not support cheaters!
Keyboard: Logitech G15 first generation - Mice: Logitech G9, G502, G602 - OS: Windows 7 Pro 64 Bit - AHK version: 1.1.29.00
User avatar
Flipeador
Posts: 1018
Joined: 15 Nov 2014, 21:31
GitHub: Flipeador
Location: Argentina
Contact:

Re: Create own class id for ahk gui?

Post by Flipeador » 21 Jul 2018, 19:27

Try this code, it is for AHKv2 because AHKv1 is MUCH slower. Create a copy of AutoHotkey.exe and select it in the dialog box.

Code: Select all

ahkexe := FileSelect()
if (!ErrorLevel)
    MsgBox SetAHKClassName(ahkexe, InputBox(,,,"FlipeadorGUI"))
ExitApp

SetAHKClassName(File, Name)
{
    local f := FileOpen(File, "rw-wd", "UTF-16-RAW")
    if (!f)
        return FALSE

    local Buffer := ""
    VarSetCapacity(Buffer, 28)
    while (!f.AtEOF)
    {
        f.RawRead(&Buffer, 26)
        if (StrGet(&Buffer, 13, "UTF-16") == "AutoHotkeyGUI")
        {
            f.pos := f.pos - 2*13, f.Write(Name)
            loop 13 - StrLen(Name)
                f.WriteUShort(0)
            return TRUE
        }
        f.Seek(A_Index+1)
    }

    return FALSE
}
Anyway, this is a VERY bad idea. You should look for a smarter alternative to ahk_class.
Edit: You can try this for v1.
Spoiler
Windws 1♂ Pro 64-Bits I make scripts for AHKv2 (my v2 compiler) & WIN_7+ Spanish Argentina SublimeText 3 & AHKv2 My GDI+ Library
AHKStudent
Posts: 308
Joined: 05 May 2018, 12:23

Re: Create own class id for ahk gui?

Post by AHKStudent » 22 Jul 2018, 08:31

Interesting, how can I do this manually? when I try to open the exe in txt I do not find AutoHotkeyGUI
User avatar
Flipeador
Posts: 1018
Joined: 15 Nov 2014, 21:31
GitHub: Flipeador
Location: Argentina
Contact:

Re: Create own class id for ahk gui?

Post by Flipeador » 22 Jul 2018, 09:57

AHKStudent wrote:Interesting, how can I do this manually? when I try to open the exe in txt I do not find AutoHotkeyGUI
Open it in a hexadecimal editor like HxD.
Edit: I tried doing it in a running script with GetAddressOfData (v2) but it did not work :lol:
Windws 1♂ Pro 64-Bits I make scripts for AHKv2 (my v2 compiler) & WIN_7+ Spanish Argentina SublimeText 3 & AHKv2 My GDI+ Library
AHKStudent
Posts: 308
Joined: 05 May 2018, 12:23

Re: Create own class id for ahk gui?

Post by AHKStudent » 22 Jul 2018, 13:02

Flipeador wrote:
AHKStudent wrote:Interesting, how can I do this manually? when I try to open the exe in txt I do not find AutoHotkeyGUI
Open it in a hexadecimal editor like HxD.
Edit: I tried doing it in a running script with GetAddressOfData (v2) but it did not work :lol:
I tried HxD, I select my exe, I do a search for the word AutoHotkeyGUI and it finds nothing, but your script works. I tried with a exe that did not have the changed name yet.
User avatar
jeeswg
Posts: 5136
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Create own class id for ahk gui?

Post by jeeswg » 22 Jul 2018, 14:22

- Here's a script I wrote to change 'AutoHotkeyGUI' to something else, live, while the exe is open, rather than editing the exe file.
test whether another script's hotkeys are still working (trigger hotkeys in another script) - AutoHotkey Community
https://autohotkey.com/boards/viewtopic ... 92#p132392
- But I agree, it ought to be possible to choose a custom class name for GUIs, and I mentioned it in my Wish List 2.0.
Wish List 2.0 - AutoHotkey Community
https://autohotkey.com/boards/viewtopic ... 13&t=36789
User avatar
Flipeador
Posts: 1018
Joined: 15 Nov 2014, 21:31
GitHub: Flipeador
Location: Argentina
Contact:

Re: Create own class id for ahk gui?

Post by Flipeador » 23 Jul 2018, 10:29

AHKStudent wrote:I tried HxD, I select my exe, I do a search for the word AutoHotkeyGUI and it finds nothing
Image
Windws 1♂ Pro 64-Bits I make scripts for AHKv2 (my v2 compiler) & WIN_7+ Spanish Argentina SublimeText 3 & AHKv2 My GDI+ Library
AHKStudent
Posts: 308
Joined: 05 May 2018, 12:23

Re: Create own class id for ahk gui?

Post by AHKStudent » 23 Jul 2018, 10:33

Flipeador wrote:
AHKStudent wrote:I tried HxD, I select my exe, I do a search for the word AutoHotkeyGUI and it finds nothing
works :thumbup: :thumbup: :thumbup:
User avatar
Scr1pter
Posts: 429
Joined: 06 Aug 2017, 08:21
Location: Germany

Re: Create own class id for ahk gui?

Post by Scr1pter » 24 Jul 2018, 06:16

Hi, thanks for the many replies!
Very interesting indeed.

A question:
Let's say I create a bigger script which contains single scripts (for different applications for example).
If I have several Guis and compile the big script to an Exe, will a hex editor show me several AutoHotKeyGui class ids?

If yes, I assume that the first found will be the first gui, the second the second gui etc.
So I guess I could simply rename those IDs even though they are in 1 big script?

Regards
I'm not an expert, just an enthusiastic AutoHotkey user. 8-)
Please do not support cheaters!
Keyboard: Logitech G15 first generation - Mice: Logitech G9, G502, G602 - OS: Windows 7 Pro 64 Bit - AHK version: 1.1.29.00
Post Reply

Return to “Ask For Help”