context menu window messages: focus/invoke item Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
User avatar
jeeswg
Posts: 6469
Joined: 19 Dec 2016, 01:58
Location: UK

context menu window messages: focus/invoke item  Topic is solved

31 Oct 2017, 07:26

I've been preparing a general list of window messages, and comparing against various sources.
[EDIT:] Here is that list:
List of Windows Messages - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=7&t=39218

Here I found various 'MN_' window messages:
List of windows messages with their description WM_ - General Programming - GameDev.net
http://www.gamedev.net/topic/552982-lis ... ption-wm_/

Code: Select all

;MN_SETHMENU := 0x1E0
;MN_GETHMENU := 0x1E1
;MN_SIZEWINDOW := 0x1E2
;MN_OPENHIERARCHY := 0x1E3
;MN_CLOSEHIERARCHY := 0x1E4
;MN_SELECTITEM := 0x1E5
;MN_CANCELMENUS := 0x1E6
;MN_SELECTFIRSTVALIDITEM := 0x1E7
;MN_GETPPOPUPMENU := 0x1EA
;MN_FINDMENUWINDOWFROMPOINT := 0x1EB
;MN_SHOWPOPUPWINDOW := 0x1EC
;MN_BUTTONDOWN := 0x1ED
;MN_MOUSEMOVE := 0x1EE
;MN_BUTTONUP := 0x1EF
;MN_SETTIMERTOOPENHIERARCHY := 0x1F0
;MN_DBLCLK := 0x1F1
Note: when I checked the .h files in C:\Program Files (x86)\Windows Kits\8.1, the only one of those 'MN_' messages that I found a reference to was MN_GETHMENU, in WinUser.h.

I'd been using MN_GETHMENU a lot in the past, and there are quite a few results for: AutoHotkey MN_GETHMENU. But I couldn't find any results for AutoHotkey and any of the other messages. E.g. I tried searching for 'AutoHotkey MN_SELECTITEM/MN_DBLCLK' and 'Post/SendMessage, 497/0x1F1/485/0x1E5'.

I don't have any documentation for the messages currently, but I've worked out a few things:

Code: Select all

q:: ;menus - focus the nth item
vIndex := 3
PostMessage, 0x1E5, % vIndex-1, 0,, ahk_class #32768 ;MN_SELECTITEM := 0x1E5
return

w:: ;menus - invoke the nth item
vIndex := 3
PostMessage, 0x1F1, % vIndex-1, 0,, ahk_class #32768 ;MN_DBLCLK := 0x1F1
return

e:: ;menus - cancel menu and any visible submenus
PostMessage, 0x1E6,,,, ahk_class #32768 ;MN_CANCELMENUS := 0x1E6
return

r:: ;menus - focus the first valid item
PostMessage, 0x1E7,,,, ahk_class #32768 ;MN_SELECTFIRSTVALIDITEM := 0x1E7
return

t:: ;menus - get menu handle
SendMessage, 0x1E1,,,, ahk_class #32768 ;MN_GETHMENU := 0x1E1
hMenu := ErrorLevel
MsgBox, % hMenu
return
I'd wanted something like this for a long time, probably since I started using AutoHotkey. I have been able to invoke items via the Acc library, but I'd been curious that I'd never found any other way to programmatically invoke a menu item, since I perceived Acc as essentially being a wrapper for the Winapi messages and functions. I'm quite pleased that I can now do this, without using the Acc functions.

I'm posting in Ask For Help, rather than Scripts and Functions, in case anyone has any other information or anything else interesting to add. Cheers.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA

Return to “Ask For Help”

Who is online

Users browsing this forum: Bing [Bot], Google [Bot], vsub and 210 guests