list of AutoHotkey WM_COMMAND IDs (e.g. Reload/Edit/Suspend/ListVars on another script)

Helpful script writing tricks and HowTo's
User avatar
jeeswg
Posts: 2055
Joined: 19 Dec 2016, 01:58
Location: UK

list of AutoHotkey WM_COMMAND IDs (e.g. Reload/Edit/Suspend/ListVars on another script)

06 Feb 2017, 10:16

I had noticed that certain AutoHotkey commands
had multiple WM_COMMAND IDs e.g. reload (65400 and 65303),
which was making it hard to maintain certain scripts.
So I decided to investigate and then choose a preferred
ID number where two were available.

==================================================

from AutoHotkey-master\Source\resources\resource.h (AutoHotkey v1.0.48.05 'AutoHotkey Basic' source code):
GitHub - AutoHotkey/AutoHotkey: AutoHotkey is a powerful and easy to use scripting language for desktop automation on Windows.
https://github.com/AutoHotkey/AutoHotkey

// Since WM_COMMAND IDs must be shared among all menus and controls, they are carefully conserved,
// especially since there are only 65,535 possible IDs. In addition, they are assigned to ranges
// to minimize the need that they will need to be changed in the future (changing the ID of a main
// menu item, tray menu item, or a user-defined menu item [by way of increasing MAX_CONTROLS_PER_GUI]
// is bad because some scripts might be using PostMessage/SendMessage to automate AutoHotkey itself).
// For this reason, the following ranges are reserved:
// 0: unused (possibly special in some contexts)
// 1: IDOK
// 2: IDCANCEL
// 3 to 1002: GUI window control IDs (these IDs must be unique only within their parent, not across all GUI windows)
// 1003 to 65299: User Defined Menu IDs
// 65300 to 65399: Standard tray menu items.
// 65400 to 65534: main menu items (might be best to leave 65535 unused in case it ever has special meaning)

IDs 65300-65307 and IDs 65400-65413:

ID_TRAY_OPEN := 65300
ID_FILE_RELOADSCRIPT := 65400 ;ID_TRAY_RELOADSCRIPT := 65303
ID_FILE_EDITSCRIPT := 65401 ;ID_TRAY_EDITSCRIPT := 65304
ID_FILE_WINDOWSPY := 65402 ;ID_TRAY_WINDOWSPY := 65302
ID_FILE_PAUSE := 65403 ;ID_TRAY_PAUSE := 65306
ID_FILE_SUSPEND := 65404 ;ID_TRAY_SUSPEND := 65305
ID_FILE_EXIT := 65405 ;ID_TRAY_EXIT := 65307
ID_VIEW_LINES := 65406
ID_VIEW_VARIABLES := 65407
ID_VIEW_HOTKEYS := 65408
ID_VIEW_KEYHISTORY := 65409
ID_VIEW_REFRESH := 65410
ID_HELP_USERMANUAL := 65411 ;ID_TRAY_HELP := 65301
ID_HELP_WEBSITE := 65412

==================================================

From:
Autohotkey-scripts-.ahk/AHKControl.ahk at master · Drugoy/Autohotkey-scripts-.ahk · GitHub
https://github.com/Drugoy/Autohotkey-scripts-.ahk/blob/master/ScriptManager.ahk/AHKControl.ahk

formerly at: autohotkey.net/~Lexikos/AHKControl/AHKControl.ahk

Cmd_Open = 65300
;-
Cmd_Reload = 65400
Cmd_Edit = 65401
Cmd_Pause = 65403
Cmd_Suspend = 65404
;-
Cmd_ViewLines = 65406
Cmd_ViewVariables = 65407
Cmd_ViewHotkeys = 65408
Cmd_ViewKeyHistory = 65409
;-
Cmd_Exit = 65405

missing from AHKControl.ahk list:
ID_FILE_WINDOWSPY := 65402 ;ID_TRAY_WINDOWSPY := 65302
ID_VIEW_REFRESH := 65410
ID_HELP_USERMANUAL := 65411 ;ID_TRAY_HELP := 65301
ID_HELP_WEBSITE := 65412

==================================================

Note: files inside source code zips/exes seem to differ:
GitHub - AutoHotkey/AutoHotkey: AutoHotkey is a powerful and easy to use scripting language for desktop automation on Windows.
https://github.com/AutoHotkey/AutoHotkey
Index of /download/1.0
https://autohotkey.com/download/1.0/

Note: the following opens the script with notepad.exe by default:
ID_FILE_EDITSCRIPT := 65401 ;ID_TRAY_EDITSCRIPT := 65304
this can be changed at:
HKEY_CLASSES_ROOT\AutoHotkeyScript\Shell\Edit\Command

Note: the following toggle rather than set pause/suspend modes:
ID_FILE_PAUSE := 65403 ;ID_TRAY_PAUSE := 65306
ID_FILE_SUSPEND := 65404 ;ID_TRAY_SUSPEND := 65305

==================================================

Usage example:

Code: [Select all] [Download] GeSHi © Codebox Plus

q::
DetectHiddenWindows, On
SetTitleMatchMode, 2 ;A window's title can contain WinTitle anywhere
WinGet, hWnd, ID, \MyScript.ahk ahk_class AutoHotkey
PostMessage, 0x111, 65405,,, % "ahk_id " hWnd ;WM_COMMAND := 0x111 ;ID_FILE_EXIT := 65405
return
User avatar
jeeswg
Posts: 2055
Joined: 19 Dec 2016, 01:58
Location: UK

Re: list of AutoHotkey WM_COMMAND IDs (e.g. Reload/Edit/Suspend/ListVars on another script)

06 Jul 2017, 22:26

Code to choose alternative hotkeys for interacting with the main window, and to be able to interact with it while a MsgBox or other dialog is open.

program
https://autohotkey.com/docs/program.html
Known issue: Keyboard shortcuts for menu items do not work while the script is displaying a MsgBox or other dialog.

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

Helgef
Posts: 2115
Joined: 17 Jul 2016, 01:02
Contact:

Re: list of AutoHotkey WM_COMMAND IDs (e.g. Reload/Edit/Suspend/ListVars on another script)

07 Jul 2017, 03:24

This might be a handy shortcut. Thanks. :thumbup:
If I recall correctly, the suspend message toggles the suspension, do you know if there is a way to set the suspension state to either on or off?

Finally, this might be considered related, if not, you might be interested anyways,

cheers!
User avatar
jeeswg
Posts: 2055
Joined: 19 Dec 2016, 01:58
Location: UK

Re: list of AutoHotkey WM_COMMAND IDs (e.g. Reload/Edit/Suspend/ListVars on another script)

07 Jul 2017, 04:39

To set the Suspend state to on/off, I'd get the state and either toggle or not as appropriate, see the script below. Suspend has On/Off parameters it turns out, I don't really use it that much.

Thanks for the link, if there's a specific detail you had in mind, please say so. Cheers.

Well, to make a versatile script that could suspend itself and/or others, was slightly more involved than the one-liners above, but thanks for the idea. I've made it about as simple as I can, any improvements/suggestions are welcome.

When I wrote the small script above, I didn't realise that: inside every small script there's a big script trying to get out.

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

Last edited by jeeswg on 07 Jul 2017, 05:50, edited 1 time in total.
Helgef
Posts: 2115
Joined: 17 Jul 2016, 01:02
Contact:

Re: list of AutoHotkey WM_COMMAND IDs (e.g. Reload/Edit/Suspend/ListVars on another script)

07 Jul 2017, 04:54

Hello, thanks for you efforts, I shall take a look.
The specific detail I had in mind was ahk's internal usage of the message 0x44.

Cheers.
Helgef
Posts: 2115
Joined: 17 Jul 2016, 01:02
Contact:

Re: list of AutoHotkey WM_COMMAND IDs (e.g. Reload/Edit/Suspend/ListVars on another script)

07 Jul 2017, 05:22

Excellent jeeswg! :bravo:
This is what I wanted,

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus


Example usage,

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

User avatar
jeeswg
Posts: 2055
Joined: 19 Dec 2016, 01:58
Location: UK

Re: list of AutoHotkey WM_COMMAND IDs (e.g. Reload/Edit/Suspend/ListVars on another script)

07 Jul 2017, 05:34

Btw CloseHandle is wrong, it doesn't do menu handles. I'll have to investigate ...

[EDIT:] DeleteObject doesn't work either. It may be simply that you don't close it, it's just a read-only global ID you retrieve like an hWnd. (So I've edited my 2 functions to remove the 2 CloseHandle lines in each of them.)

Note: There is DestroyMenu, but we don't want to do that either.

Return to “Tutorials”

Who is online

Users browsing this forum: No registered users and 3 guests