Skip to content
This repository has been archived by the owner on Aug 23, 2019. It is now read-only.

Commit

Permalink
add new function [user32] DestroyMenu
Browse files Browse the repository at this point in the history
  • Loading branch information
ergoz committed Aug 11, 2019
1 parent 2f8d46e commit c8089c9
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions user32.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ var (
procUnregisterClassW = moduser32.NewProc("UnregisterClassW")
procCreatePopupMenu = moduser32.NewProc("CreatePopupMenu")
procCreateMenu = moduser32.NewProc("CreateMenu")
procDestroyMenu = moduser32.NewProc("DestroyMenu")
)

func SendMessageTimeout(hwnd HWND, msg uint32, wParam, lParam uintptr, fuFlags, uTimeout uint32, lpdwResult uintptr) uintptr {
Expand Down Expand Up @@ -1297,11 +1298,9 @@ func UnregisterClassW(lpClassName string, hInstance HINSTANCE) bool {
// See https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-createpopupmenu
func CreatePopupMenu() (HMENU, error) {
ret, _, err := procCreatePopupMenu.Call()

if ret == 0 && err.(syscall.Errno) != ERROR_SUCCESS {
return HMENU(ret), err
}

return HMENU(ret), nil
}

Expand All @@ -1310,10 +1309,18 @@ func CreatePopupMenu() (HMENU, error) {
// See https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-createmenu
func CreateMenu() (HMENU, error) {
ret, _, err := procCreateMenu.Call()

if ret == 0 && err.(syscall.Errno) != ERROR_SUCCESS {
return HMENU(ret), err
}

return HMENU(ret), nil
}

// DestroyMenu Destroys the specified menu and frees any memory that the menu occupies.
// See https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-destroymenu
func DestroyMenu(menu HMENU) (bool, error) {
ret, _, err := procDestroyMenu.Call()
if ret == 0 && err.(syscall.Errno) != ERROR_SUCCESS {
return false, err
}
return ret != 0, nil
}

0 comments on commit c8089c9

Please sign in to comment.