-
Notifications
You must be signed in to change notification settings - Fork 1
/
Menu.cs
105 lines (89 loc) · 3.33 KB
/
Menu.cs
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
using System;
using System.Runtime.InteropServices;
namespace Projzo.Interop
{
internal static class Menu
{
// The TrackPopupMenuEx function displays a shortcut menu at the specified location and tracks the selection of items on the shortcut menu. The shortcut menu can appear anywhere on the screen.
[DllImport("user32.dll", ExactSpelling = true, CharSet = CharSet.Auto)]
public static extern uint TrackPopupMenuEx(IntPtr hmenu, TPM flags, int x, int y, IntPtr hwnd, IntPtr lptpm);
// The CreatePopupMenu function creates a drop-down menu, submenu, or shortcut menu. The menu is initially empty. You can insert or append menu items by using the InsertMenuItem function. You can also use the InsertMenu function to insert menu items and the AppendMenu function to append menu items.
[DllImport("user32", SetLastError = true, CharSet = CharSet.Auto)]
public static extern IntPtr CreatePopupMenu();
// The DestroyMenu function destroys the specified menu and frees any memory that the menu occupies.
[DllImport("user32", SetLastError = true, CharSet = CharSet.Auto)]
public static extern bool DestroyMenu(IntPtr hMenu);
// Determines the default menu item on the specified menu
[DllImport("user32", SetLastError = true, CharSet = CharSet.Auto)]
public static extern int GetMenuDefaultItem(IntPtr hMenu, bool fByPos, uint gmdiFlags);
}
// Specifies how TrackPopupMenuEx positions the shortcut menu horizontally
[Flags]
public enum TPM : uint
{
LEFTBUTTON = 0x0000,
RIGHTBUTTON = 0x0002,
LEFTALIGN = 0x0000,
CENTERALIGN = 0x0004,
RIGHTALIGN = 0x0008,
TOPALIGN = 0x0000,
VCENTERALIGN = 0x0010,
BOTTOMALIGN = 0x0020,
HORIZONTAL = 0x0000,
VERTICAL = 0x0040,
NONOTIFY = 0x0080,
RETURNCMD = 0x0100,
RECURSE = 0x0001,
HORPOSANIMATION = 0x0400,
HORNEGANIMATION = 0x0800,
VERPOSANIMATION = 0x1000,
VERNEGANIMATION = 0x2000,
NOANIMATION = 0x4000,
LAYOUTRTL = 0x8000
}
// Specifies the content of the new menu item
[Flags]
public enum MFT : uint
{
GRAYED = 0x00000003,
DISABLED = 0x00000003,
CHECKED = 0x00000008,
SEPARATOR = 0x00000800,
RADIOCHECK = 0x00000200,
BITMAP = 0x00000004,
OWNERDRAW = 0x00000100,
MENUBARBREAK = 0x00000020,
MENUBREAK = 0x00000040,
RIGHTORDER = 0x00002000,
BYCOMMAND = 0x00000000,
BYPOSITION = 0x00000400,
POPUP = 0x00000010
}
// Specifies the state of the new menu item
[Flags]
public enum MFS : uint
{
GRAYED = 0x00000003,
DISABLED = 0x00000003,
CHECKED = 0x00000008,
HILITE = 0x00000080,
ENABLED = 0x00000000,
UNCHECKED = 0x00000000,
UNHILITE = 0x00000000,
DEFAULT = 0x00001000
}
// Specifies the content of the new menu item
[Flags]
public enum MIIM : uint
{
BITMAP = 0x80,
CHECKMARKS = 0x08,
DATA = 0x20,
FTYPE = 0x100,
ID = 0x02,
STATE = 0x01,
STRING = 0x40,
SUBMENU = 0x04,
TYPE = 0x10
}
}