Create own class id for ahk gui?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
Scr1pter
Posts: 1272
Joined: 06 Aug 2017, 08:21
Location: Germany

Create own class id for ahk gui?

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
Please use [code][/code] when posting code!
Keyboard: Logitech G PRO - Mouse: Logitech G502 LS - OS: Windows 10 Pro 64 Bit - AHK version: 1.1.33.09
User avatar
Flipeador
Posts: 1204
Joined: 15 Nov 2014, 21:31
Location: Argentina
Contact:

Re: Create own class id for ahk gui?

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
AHKStudent
Posts: 1472
Joined: 05 May 2018, 12:23

Re: Create own class id for ahk gui?

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: 1204
Joined: 15 Nov 2014, 21:31
Location: Argentina
Contact:

Re: Create own class id for ahk gui?

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:
AHKStudent
Posts: 1472
Joined: 05 May 2018, 12:23

Re: Create own class id for ahk gui?

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: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Create own class id for ahk gui?

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
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
User avatar
Flipeador
Posts: 1204
Joined: 15 Nov 2014, 21:31
Location: Argentina
Contact:

Re: Create own class id for ahk gui?

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
AHKStudent
Posts: 1472
Joined: 05 May 2018, 12:23

Re: Create own class id for ahk gui?

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: 1272
Joined: 06 Aug 2017, 08:21
Location: Germany

Re: Create own class id for ahk gui?

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
Please use [code][/code] when posting code!
Keyboard: Logitech G PRO - Mouse: Logitech G502 LS - OS: Windows 10 Pro 64 Bit - AHK version: 1.1.33.09

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 116 guests