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: 1029
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 http://www.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

Return to “Tutorials”

Who is online

Users browsing this forum: No registered users and 5 guests