Skip to content

Commit 7a0e89e

Browse files
committed
Define more menu manipulation functions and constants
Signed-off-by: Simon Rozman <[email protected]>
1 parent 85a11ff commit 7a0e89e

File tree

2 files changed

+197
-17
lines changed

2 files changed

+197
-17
lines changed

menu.go

Lines changed: 52 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,27 +21,27 @@ const (
2121

2222
// Constants for MENUITEMINFO.fType
2323
const (
24-
MFT_BITMAP = 4
25-
MFT_MENUBARBREAK = 32
26-
MFT_MENUBREAK = 64
27-
MFT_OWNERDRAW = 256
28-
MFT_RADIOCHECK = 512
29-
MFT_RIGHTJUSTIFY = 0x4000
30-
MFT_SEPARATOR = 0x800
31-
MFT_RIGHTORDER = 0x2000
32-
MFT_STRING = 0
24+
MFT_STRING = MF_STRING
25+
MFT_BITMAP = MF_BITMAP
26+
MFT_MENUBARBREAK = MF_MENUBARBREAK
27+
MFT_MENUBREAK = MF_MENUBREAK
28+
MFT_OWNERDRAW = MF_OWNERDRAW
29+
MFT_RADIOCHECK = 0x00000200
30+
MFT_SEPARATOR = MF_SEPARATOR
31+
MFT_RIGHTORDER = 0x00002000
32+
MFT_RIGHTJUSTIFY = MF_RIGHTJUSTIFY
3333
)
3434

3535
// Constants for MENUITEMINFO.fState
3636
const (
37-
MFS_CHECKED = 8
38-
MFS_DEFAULT = 4096
39-
MFS_DISABLED = 3
40-
MFS_ENABLED = 0
41-
MFS_GRAYED = 3
42-
MFS_HILITE = 128
43-
MFS_UNCHECKED = 0
44-
MFS_UNHILITE = 0
37+
MFS_GRAYED = 0x00000003
38+
MFS_DISABLED = MFS_GRAYED
39+
MFS_CHECKED = MF_CHECKED
40+
MFS_HILITE = MF_HILITE
41+
MFS_ENABLED = MF_ENABLED
42+
MFS_UNCHECKED = MF_UNCHECKED
43+
MFS_UNHILITE = MF_UNHILITE
44+
MFS_DEFAULT = MF_DEFAULT
4545
)
4646

4747
// Constants for MENUITEMINFO.hbmp*
@@ -80,8 +80,43 @@ const (
8080
)
8181

8282
const (
83+
// Menu flags for Add/Check/EnableMenuItem()
84+
MF_INSERT = 0x00000000
85+
MF_CHANGE = 0x00000080
86+
MF_APPEND = 0x00000100
87+
MF_DELETE = 0x00000200
88+
MF_REMOVE = 0x00001000
89+
8390
MF_BYCOMMAND = 0x00000000
8491
MF_BYPOSITION = 0x00000400
92+
93+
MF_SEPARATOR = 0x00000800
94+
95+
MF_ENABLED = 0x00000000
96+
MF_GRAYED = 0x00000001
97+
MF_DISABLED = 0x00000002
98+
99+
MF_UNCHECKED = 0x00000000
100+
MF_CHECKED = 0x00000008
101+
MF_USECHECKBITMAPS = 0x00000200
102+
103+
MF_STRING = 0x00000000
104+
MF_BITMAP = 0x00000004
105+
MF_OWNERDRAW = 0x00000100
106+
107+
MF_POPUP = 0x00000010
108+
MF_MENUBARBREAK = 0x00000020
109+
MF_MENUBREAK = 0x00000040
110+
111+
MF_UNHILITE = 0x00000000
112+
MF_HILITE = 0x00000080
113+
114+
MF_DEFAULT = 0x00001000
115+
MF_SYSMENU = 0x00002000
116+
MF_HELP = 0x00004000
117+
MF_RIGHTJUSTIFY = 0x00004000
118+
119+
MF_MOUSESELECT = 0x00008000
85120
)
86121

87122
type MENUITEMINFO struct {

user32.go

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1775,6 +1775,7 @@ var (
17751775
createWindowEx *windows.LazyProc
17761776
deferWindowPos *windows.LazyProc
17771777
defWindowProc *windows.LazyProc
1778+
deleteMenu *windows.LazyProc
17781779
destroyIcon *windows.LazyProc
17791780
destroyMenu *windows.LazyProc
17801781
destroyWindow *windows.LazyProc
@@ -1785,6 +1786,7 @@ var (
17851786
drawFocusRect *windows.LazyProc
17861787
drawTextEx *windows.LazyProc
17871788
emptyClipboard *windows.LazyProc
1789+
enableMenuItem *windows.LazyProc
17881790
enableWindow *windows.LazyProc
17891791
endDeferWindowPos *windows.LazyProc
17901792
endDialog *windows.LazyProc
@@ -1806,12 +1808,17 @@ var (
18061808
getForegroundWindow *windows.LazyProc
18071809
getIconInfo *windows.LazyProc
18081810
getKeyState *windows.LazyProc
1811+
getMenuCheckMarkDimensions *windows.LazyProc
18091812
getMenuInfo *windows.LazyProc
1813+
getMenuItemCount *windows.LazyProc
1814+
getMenuItemID *windows.LazyProc
1815+
getMenuItemInfo *windows.LazyProc
18101816
getMessage *windows.LazyProc
18111817
getMonitorInfo *windows.LazyProc
18121818
getParent *windows.LazyProc
18131819
getRawInputData *windows.LazyProc
18141820
getScrollInfo *windows.LazyProc
1821+
getSubMenu *windows.LazyProc
18151822
getSysColor *windows.LazyProc
18161823
getSysColorBrush *windows.LazyProc
18171824
getSystemMenu *windows.LazyProc
@@ -1848,6 +1855,7 @@ var (
18481855
peekMessage *windows.LazyProc
18491856
postMessage *windows.LazyProc
18501857
postQuitMessage *windows.LazyProc
1858+
redrawWindow *windows.LazyProc
18511859
registerClassEx *windows.LazyProc
18521860
registerRawInputDevices *windows.LazyProc
18531861
registerWindowMessage *windows.LazyProc
@@ -1868,6 +1876,7 @@ var (
18681876
setMenu *windows.LazyProc
18691877
setMenuDefaultItem *windows.LazyProc
18701878
setMenuInfo *windows.LazyProc
1879+
setMenuItemBitmaps *windows.LazyProc
18711880
setMenuItemInfo *windows.LazyProc
18721881
setParent *windows.LazyProc
18731882
setRect *windows.LazyProc
@@ -1881,6 +1890,7 @@ var (
18811890
showWindow *windows.LazyProc
18821891
systemParametersInfo *windows.LazyProc
18831892
trackMouseEvent *windows.LazyProc
1893+
trackPopupMenu *windows.LazyProc
18841894
trackPopupMenuEx *windows.LazyProc
18851895
translateMessage *windows.LazyProc
18861896
unhookWinEvent *windows.LazyProc
@@ -1915,6 +1925,7 @@ func init() {
19151925
createWindowEx = libuser32.NewProc("CreateWindowExW")
19161926
deferWindowPos = libuser32.NewProc("DeferWindowPos")
19171927
defWindowProc = libuser32.NewProc("DefWindowProcW")
1928+
deleteMenu = libuser32.NewProc("DeleteMenu")
19181929
destroyIcon = libuser32.NewProc("DestroyIcon")
19191930
destroyMenu = libuser32.NewProc("DestroyMenu")
19201931
destroyWindow = libuser32.NewProc("DestroyWindow")
@@ -1925,6 +1936,7 @@ func init() {
19251936
drawMenuBar = libuser32.NewProc("DrawMenuBar")
19261937
drawTextEx = libuser32.NewProc("DrawTextExW")
19271938
emptyClipboard = libuser32.NewProc("EmptyClipboard")
1939+
enableMenuItem = libuser32.NewProc("EnableMenuItem")
19281940
enableWindow = libuser32.NewProc("EnableWindow")
19291941
endDeferWindowPos = libuser32.NewProc("EndDeferWindowPos")
19301942
endDialog = libuser32.NewProc("EndDialog")
@@ -1946,12 +1958,17 @@ func init() {
19461958
getForegroundWindow = libuser32.NewProc("GetForegroundWindow")
19471959
getIconInfo = libuser32.NewProc("GetIconInfo")
19481960
getKeyState = libuser32.NewProc("GetKeyState")
1961+
getMenuCheckMarkDimensions = libuser32.NewProc("GetMenuCheckMarkDimensions")
19491962
getMenuInfo = libuser32.NewProc("GetMenuInfo")
1963+
getMenuItemCount = libuser32.NewProc("GetMenuItemCount")
1964+
getMenuItemID = libuser32.NewProc("GetMenuItemID")
1965+
getMenuItemInfo = libuser32.NewProc("GetMenuItemInfoW")
19501966
getMessage = libuser32.NewProc("GetMessageW")
19511967
getMonitorInfo = libuser32.NewProc("GetMonitorInfoW")
19521968
getParent = libuser32.NewProc("GetParent")
19531969
getRawInputData = libuser32.NewProc("GetRawInputData")
19541970
getScrollInfo = libuser32.NewProc("GetScrollInfo")
1971+
getSubMenu = libuser32.NewProc("GetSubMenu")
19551972
getSysColor = libuser32.NewProc("GetSysColor")
19561973
getSysColorBrush = libuser32.NewProc("GetSysColorBrush")
19571974
getSystemMenu = libuser32.NewProc("GetSystemMenu")
@@ -1993,6 +2010,7 @@ func init() {
19932010
peekMessage = libuser32.NewProc("PeekMessageW")
19942011
postMessage = libuser32.NewProc("PostMessageW")
19952012
postQuitMessage = libuser32.NewProc("PostQuitMessage")
2013+
redrawWindow = libuser32.NewProc("RedrawWindow")
19962014
registerClassEx = libuser32.NewProc("RegisterClassExW")
19972015
registerRawInputDevices = libuser32.NewProc("RegisterRawInputDevices")
19982016
registerWindowMessage = libuser32.NewProc("RegisterWindowMessageW")
@@ -2013,6 +2031,7 @@ func init() {
20132031
setMenu = libuser32.NewProc("SetMenu")
20142032
setMenuDefaultItem = libuser32.NewProc("SetMenuDefaultItem")
20152033
setMenuInfo = libuser32.NewProc("SetMenuInfo")
2034+
setMenuItemBitmaps = libuser32.NewProc("SetMenuItemBitmaps")
20162035
setMenuItemInfo = libuser32.NewProc("SetMenuItemInfoW")
20172036
setRect = libuser32.NewProc("SetRect")
20182037
setParent = libuser32.NewProc("SetParent")
@@ -2031,6 +2050,7 @@ func init() {
20312050
showWindow = libuser32.NewProc("ShowWindow")
20322051
systemParametersInfo = libuser32.NewProc("SystemParametersInfoW")
20332052
trackMouseEvent = libuser32.NewProc("TrackMouseEvent")
2053+
trackPopupMenu = libuser32.NewProc("TrackPopupMenu")
20342054
trackPopupMenuEx = libuser32.NewProc("TrackPopupMenuEx")
20352055
translateMessage = libuser32.NewProc("TranslateMessage")
20362056
unhookWinEvent = libuser32.NewProc("UnhookWinEvent")
@@ -2252,6 +2272,15 @@ func DefWindowProc(hWnd HWND, Msg uint32, wParam, lParam uintptr) uintptr {
22522272
return ret
22532273
}
22542274

2275+
func DeleteMenu(hMenu HMENU, uPosition uint32, uFlags uint32) bool {
2276+
ret, _, _ := syscall.Syscall(deleteMenu.Addr(), 3,
2277+
uintptr(hMenu),
2278+
uintptr(uPosition),
2279+
uintptr(uFlags))
2280+
2281+
return ret != 0
2282+
}
2283+
22552284
func DestroyIcon(hIcon HICON) bool {
22562285
ret, _, _ := syscall.Syscall(destroyIcon.Addr(), 1,
22572286
uintptr(hIcon),
@@ -2354,6 +2383,15 @@ func EmptyClipboard() bool {
23542383
return ret != 0
23552384
}
23562385

2386+
func EnableMenuItem(hMenu HMENU, uIDEnableItem uint32, uEnable uint32) bool {
2387+
ret, _, _ := syscall.Syscall(enableMenuItem.Addr(), 3,
2388+
uintptr(hMenu),
2389+
uintptr(uIDEnableItem),
2390+
uintptr(uEnable))
2391+
2392+
return ret != 0
2393+
}
2394+
23572395
func EnableWindow(hWnd HWND, bEnable bool) bool {
23582396
ret, _, _ := syscall.Syscall(enableWindow.Addr(), 2,
23592397
uintptr(hWnd),
@@ -2552,6 +2590,15 @@ func GetKeyState(nVirtKey int32) int16 {
25522590
return int16(ret)
25532591
}
25542592

2593+
func GetMenuCheckMarkDimensions() int32 {
2594+
ret, _, _ := syscall.Syscall(getMenuCheckMarkDimensions.Addr(), 0,
2595+
0,
2596+
0,
2597+
0)
2598+
2599+
return int32(ret)
2600+
}
2601+
25552602
func GetMenuInfo(hmenu HMENU, lpcmi *MENUINFO) bool {
25562603
ret, _, _ := syscall.Syscall(getMenuInfo.Addr(), 2,
25572604
uintptr(hmenu),
@@ -2561,6 +2608,36 @@ func GetMenuInfo(hmenu HMENU, lpcmi *MENUINFO) bool {
25612608
return ret != 0
25622609
}
25632610

2611+
func GetMenuItemCount(hMenu HMENU) int32 {
2612+
ret, _, _ := syscall.Syscall(getMenuItemCount.Addr(), 1,
2613+
uintptr(hMenu),
2614+
0,
2615+
0)
2616+
2617+
return int32(ret)
2618+
}
2619+
2620+
func GetMenuItemID(hMenu HMENU, nPos int32) uint32 {
2621+
ret, _, _ := syscall.Syscall(getMenuItemID.Addr(), 2,
2622+
uintptr(hMenu),
2623+
uintptr(nPos),
2624+
0)
2625+
2626+
return uint32(ret)
2627+
}
2628+
2629+
func GetMenuItemInfo(hmenu HMENU, item uint32, fByPosition BOOL, lpmii *MENUITEMINFO) bool {
2630+
ret, _, _ := syscall.Syscall6(getMenuItemInfo.Addr(), 4,
2631+
uintptr(hmenu),
2632+
uintptr(item),
2633+
uintptr(fByPosition),
2634+
uintptr(unsafe.Pointer(lpmii)),
2635+
0,
2636+
0)
2637+
2638+
return ret != 0
2639+
}
2640+
25642641
func GetMessage(msg *MSG, hWnd HWND, msgFilterMin, msgFilterMax uint32) BOOL {
25652642
ret, _, _ := syscall.Syscall6(getMessage.Addr(), 4,
25662643
uintptr(unsafe.Pointer(msg)),
@@ -2612,6 +2689,15 @@ func GetScrollInfo(hwnd HWND, fnBar int32, lpsi *SCROLLINFO) bool {
26122689
return ret != 0
26132690
}
26142691

2692+
func GetSubMenu(hMenu HMENU, nPos int32) HMENU {
2693+
ret, _, _ := syscall.Syscall(getSubMenu.Addr(), 2,
2694+
uintptr(hMenu),
2695+
uintptr(nPos),
2696+
0)
2697+
2698+
return HMENU(ret)
2699+
}
2700+
26152701
func GetSysColor(nIndex int) uint32 {
26162702
ret, _, _ := syscall.Syscall(getSysColor.Addr(), 1,
26172703
uintptr(nIndex),
@@ -2964,6 +3050,38 @@ func PostQuitMessage(exitCode int32) {
29643050
0)
29653051
}
29663052

3053+
const (
3054+
// RedrawWindow() flags
3055+
RDW_INVALIDATE = 0x0001
3056+
RDW_INTERNALPAINT = 0x0002
3057+
RDW_ERASE = 0x0004
3058+
3059+
RDW_VALIDATE = 0x0008
3060+
RDW_NOINTERNALPAINT = 0x0010
3061+
RDW_NOERASE = 0x0020
3062+
3063+
RDW_NOCHILDREN = 0x0040
3064+
RDW_ALLCHILDREN = 0x0080
3065+
3066+
RDW_UPDATENOW = 0x0100
3067+
RDW_ERASENOW = 0x0200
3068+
3069+
RDW_FRAME = 0x0400
3070+
RDW_NOFRAME = 0x0800
3071+
)
3072+
3073+
func RedrawWindow(hWnd HWND, lprcUpdate *RECT, hrgnUpdate HRGN, flags uint32) bool {
3074+
ret, _, _ := syscall.Syscall6(redrawWindow.Addr(), 4,
3075+
uintptr(hWnd),
3076+
uintptr(unsafe.Pointer(lprcUpdate)),
3077+
uintptr(hrgnUpdate),
3078+
uintptr(flags),
3079+
0,
3080+
0)
3081+
3082+
return ret != 0
3083+
}
3084+
29673085
func RegisterClassEx(windowClass *WNDCLASSEX) ATOM {
29683086
ret, _, _ := syscall.Syscall(registerClassEx.Addr(), 1,
29693087
uintptr(unsafe.Pointer(windowClass)),
@@ -3151,6 +3269,18 @@ func SetMenuInfo(hmenu HMENU, lpcmi *MENUINFO) bool {
31513269
return ret != 0
31523270
}
31533271

3272+
func SetMenuItemBitmaps(hMenu HMENU, uPosition uint32, uFlags uint32, hBitmapUnchecked HBITMAP, hBitmapChecked HBITMAP) bool {
3273+
ret, _, _ := syscall.Syscall6(setMenuItemBitmaps.Addr(), 5,
3274+
uintptr(hMenu),
3275+
uintptr(uPosition),
3276+
uintptr(uFlags),
3277+
uintptr(hBitmapUnchecked),
3278+
uintptr(hBitmapChecked),
3279+
0)
3280+
3281+
return ret != 0
3282+
}
3283+
31543284
func SetMenuItemInfo(hMenu HMENU, uItem uint32, fByPosition bool, lpmii *MENUITEMINFO) bool {
31553285
ret, _, _ := syscall.Syscall6(setMenuItemInfo.Addr(), 4,
31563286
uintptr(hMenu),
@@ -3300,6 +3430,21 @@ func TrackMouseEvent(lpEventTrack *TRACKMOUSEEVENT) bool {
33003430
return ret != 0
33013431
}
33023432

3433+
func TrackPopupMenu(hMenu HMENU, uFlags uint32, x, y int32, nReserved int32, hWnd HWND, prcRect *RECT) uint32 {
3434+
ret, _, _ := syscall.Syscall9(trackPopupMenu.Addr(), 7,
3435+
uintptr(hMenu),
3436+
uintptr(uFlags),
3437+
uintptr(x),
3438+
uintptr(y),
3439+
uintptr(nReserved),
3440+
uintptr(hWnd),
3441+
uintptr(unsafe.Pointer(prcRect)),
3442+
0,
3443+
0)
3444+
3445+
return uint32(ret)
3446+
}
3447+
33033448
func TrackPopupMenuEx(hMenu HMENU, fuFlags uint32, x, y int32, hWnd HWND, lptpm *TPMPARAMS) BOOL {
33043449
ret, _, _ := syscall.Syscall6(trackPopupMenuEx.Addr(), 6,
33053450
uintptr(hMenu),

0 commit comments

Comments
 (0)