This repository has been archived by the owner on Nov 7, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
PopupMenuUtils.ahk
77 lines (63 loc) · 2.56 KB
/
PopupMenuUtils.ahk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
; https://autohotkey.com/board/topic/16457-controlling-popup-menues/
PopupMenuUtils_user32_handle(fn)
{
static u32 := DllCall("GetModuleHandle", Str, "user32.dll", "Ptr")
return DllCall("GetProcAddress", "Ptr", u32, "AStr", fn, "Ptr")
}
PopupMenuUtils_MF_BYPOSITION() {
return 0x00000400
}
PopupMenuUtils_GetMenuItemCount(hMenu)
{
static GetMenuItemCount := PopupMenuUtils_user32_handle("GetMenuItemCount")
return DllCall(GetMenuItemCount, "Ptr", hMenu, "Int")
}
;PopupMenuUtils_GetMenuString(hMenu, nPos)
;{
; static GetMenuStringW := PopupMenuUtils_user32_handle("GetMenuStringW"), byp := PopupMenuUtils_MF_BYPOSITION()
; if ((hMenu) && (length := DllCall(GetMenuStringW, "Ptr", hMenu, "UInt", nPos, "Ptr", 0, "Int", 0, "UInt", byp))) {
; length += 1, VarSetCapacity(lpString, (length * 2) + 2)
; if (DllCall(GetMenuStringW, "Ptr", hMenu, "UInt", nPos, "WStr", lpString, "Int", length, "UInt", byp))
; return lpString
; }
; return ""
;}
PopupMenuUtils_GetMenuString(hMenu, nPos)
{
static lpString, GetMenuStringW := PopupMenuUtils_user32_handle("GetMenuStringW"), byp := PopupMenuUtils_MF_BYPOSITION()
if !VarSetCapacity(lpString)
VarSetCapacity(lpString, 1024) ; what sort of idiot makes a menu item have ~510 characters, anyway?
if (DllCall(GetMenuStringW, "Ptr", hMenu, "UInt", nPos, "WStr", lpString, "Int", 511, "UInt", byp))
return lpString
}
PopupMenuUtils_GetMenuState(hMenu, nPos)
{
static GetMenuState := PopupMenuUtils_user32_handle("GetMenuState"), byp := PopupMenuUtils_MF_BYPOSITION()
return DllCall(GetMenuState, "Ptr", hMenu, "UInt", nPos, "UInt", byp, "UInt")
}
PopupMenuUtils_ItemIsChecked(State) {
return !!(State & 0x00000008) ; MF_CHECKED
}
PopupMenuUtils_ItemIsDisabled(State) {
return !!(State & 0x00000002 || State & 0x00000001) ; MF_DISABLED || MF_GRAYED
}
PopupMenuUtils_ItemIsPopup(State) {
return !!(State & 0x00000010) ; MF_POPUP
}
PopupMenuUtils_GetMenuItemID(hMenu, nPos) {
return DllCall("GetMenuItemID", "Ptr", hMenu, "int", nPos, "UInt")
}
PopupMenuUtils_GetHmenuFromHwnd(hWnd)
{
static SendMessagePtr := PopupMenuUtils_user32_handle(A_IsUnicode ? "SendMessageW" : "SendMessageA")
return DllCall(SendMessagePtr, "Ptr", hWnd, "UInt", 0x01E1, "Ptr", 0, "Ptr", 0, "Ptr") ; MN_GETHMENU
}
PopupMenuUtils_GetMenu(hwnd) {
return DllCall("GetMenu", "Ptr", hwnd, "Ptr")
}
PopupMenuUtils_GetSubmenu(hMenu, nPos) {
return DllCall("GetSubMenu", "Ptr", hMenu, "int", nPos, "Ptr")
}
PopupMenuUtils_WinHasMenu(WinTitle:="") {
return !!PopupMenuUtils_GetMenu(WinExist(WinTitle))
}