Немного поправил, но до нормального варианта далеко.
#SingleInstance Force
#NoEnv
SetBatchLines -1
#Persistent
CoordMode, Mouse
StringCaseSense, Locale
SetWinEventHook("EVENT_OBJECT_SHOW", 0x8002)
SetWinEventHook("EVENT_OBJECT_DESTROY", 0x8001)
Return
#If hWndMenu
LShift::
NoRemove := 1
WinClose, ahk_id %hWndMenu%
MouseMove, menuX, menuY, 0
Click Right
KeyWait LShift
NoRemove := 0
If !hWndMenu
Return
WinClose, ahk_id %hWndMenu%
MouseMove, menuX, menuY, 0
Click Right
Return
#If
RemoveMenu(hWnd) {
Global hWndMenu, menuX, menuY
SendMessage, 0x1E1, 0, 0, , ahk_id %hwnd% ; MN_GETHMENU
If !(hMenu := ErrorLevel)
Return
WinSet, Region, 0-0 w0 h0, % "ahk_id " hwnd
MouseGetPos, menuX, menuY
hWndMenu := hWnd
Loop, % DllCall("GetMenuItemCount", "Uint", hMenu) + Index := 0
{
idx := Index++
idn := DllCall("GetMenuItemID", "Uint", hMenu, "Int", idx)
nSize++ := DllCall("GetMenuString", "Uint", hMenu, "Int", idx, "Uint", 0, "Int", 0, "Uint", 0x400)
nSize := (nSize * (A_IsUnicode ? 2 : 1))
VarSetCapacity(String, nSize)
DllCall("GetMenuString", "Uint", hMenu, "Int", idx, "Str", String, "Int", nSize, "Uint", 0x400) ; MF_BYPOSITION
StringReplace, String, String, &, , 1
If String not in открыть,изменить,вырезать,копировать,создать ярлык,удалить,переименовать,свойства
DllCall("RemoveMenu", "Int", hMenu, "UInt", idx, "Uint", "0x00000400"), Index--
}
WinMove, % "ahk_id " hwnd, , menuX, menuY
WinSet, Region, , % "ahk_id " hwnd
}
EVENT_OBJECT_SHOW(hWinEventHook, event, hwnd, idObject, idChild) {
Global NoRemove, hWndMenu
If (idObject || idChild)
Return
WinGetClass, Class, % "ahk_id " hwnd
If Class != #32768
Return
WinGet, Process, ProcessName, % "ahk_id " hwnd
If Process != explorer.exe
Return
If NoRemove
hWndMenu := hwnd
Else
RemoveMenu(hWnd)
}
EVENT_OBJECT_DESTROY(hWinEventHook, event, hwnd, idObject, idChild) {
Global hWndMenu
If (idObject || idChild || hWndMenu != hwnd)
Return
hWndMenu := 0
}
SetWinEventHook(EventProc, eventMin, eventMax = 0)
{
Return DllCall("SetWinEventHook"
, "UInt", eventMin, "UInt", eventMax := !eventMax ? eventMin : eventMax
, "Ptr", hmodWinEventProc := 0, "Ptr", lpfnWinEventProc := RegisterCallback(EventProc, "F")
, "UInt", idProcess := 0, "UInt", idThread := 0
, "UInt", dwflags := 0x0 | 0x2, "Ptr") ; WINEVENT_OUTOFCONTEXT | WINEVENT_SKIPOWNPROCESS
}