In my tests, I was able to permanently change the status of menu items in all submenus, except for some in the Edit submenu.
A reason might be that some of those menu items have to be regularly updated, e.g. whether to enable/disable check/uncheck an item, based on whether: undo is available (Undo), text is selected (Cut/Copy/Delete), text is on the clipboard (Paste), the Edit control is empty (Find.../Find Next).
It appeared that the only items that remained disabled in the Edit submenu were: Replace..., Select All, Time/Date.
It appeared that the menu item appearances were updated immediately, even while the menu was shown. Cheers.
Code: Select all
q:: ;Notepad (Windows 7) - disable/enable menu item
WinGet, hWnd, ID, ahk_class Notepad
;using 1-based indices:
vMenuID := 1, vMenuItemID := 7 ;File, Print...
;vMenuID := 2, vMenuItemID := 13 ;Edit, Select All
;vMenuID := 3, vMenuItemID := 1 ;Format, Word Wrap
;vMenuID := 4, vMenuItemID := 1 ;View, Status Bar
;vMenuID := 5, vMenuItemID := 3 ;Help, About Notepad
hMenuBar := DllCall("user32\GetMenu", Ptr,hWnd, Ptr)
hSubMenu := DllCall("user32\GetSubMenu", Ptr,hMenuBar, Int,vMenuID-1, Ptr)
;MF_ENABLED := 0x0, MF_GRAYED := 0x1, MF_DISABLED := 0x2
;MF_BYCOMMAND := 0x0 ;MF_BYPOSITION := 0x400
DllCall("EnableMenuItem", Ptr,hSubMenu, UInt,vMenuItemID-1, UInt,0x403)
;DllCall("DrawMenuBar", Ptr,hWnd)
ToolTip disabled
Sleep 3000
DllCall("EnableMenuItem", Ptr,hSubMenu, UInt,vMenuItemID-1, UInt,0x400)
;DllCall("DrawMenuBar", Ptr,hWnd)
ToolTip enabled
Sleep 2000
ToolTip
return