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

Commit

Permalink
resolve #17 and #25
Browse files Browse the repository at this point in the history
  • Loading branch information
ergoz committed Aug 11, 2019
1 parent 4712e23 commit e6eb110
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 0 deletions.
21 changes: 21 additions & 0 deletions constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -3105,3 +3105,24 @@ const (
MF_STRING = 0x00000000
MF_UNCHECKED = 0x00000000
)

// for track menu
const (
TPM_CENTERALIGN = 0x0004
TPM_LEFTALIGN = 0x0000
TPM_RIGHTALIGN = 0x0008
TPM_BOTTOMALIGN = 0x0020
TPM_TOPALIGN = 0x0000
TPM_VCENTERALIGN = 0x0010
TPM_NONOTIFY = 0x0080
TPM_RETURNCMD = 0x0100
TPM_LEFTBUTTON = 0x0000
TPM_RIGHTBUTTON = 0x0002
TPM_HORNEGANIMATION = 0x0800
TPM_HORPOSANIMATION = 0x0400
TPM_NOANIMATION = 0x4000
TPM_VERNEGANIMATION = 0x2000
TPM_VERPOSANIMATION = 0x1000
TPM_HORIZONTAL = 0x0000
TPM_VERTICAL = 0x0040
)
5 changes: 5 additions & 0 deletions typedef.go
Original file line number Diff line number Diff line change
Expand Up @@ -1366,3 +1366,8 @@ type PNOTIFYICONDATA struct {
GuidItem GUID
BalloonIcon HICON
}

type TPMPARAMS struct {
cbSize uint
rcExclude RECT
}
41 changes: 41 additions & 0 deletions user32.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ var (
procDeleteMenu = moduser32.NewProc("DeleteMenu")
procAppendMenuW = moduser32.NewProc("AppendMenuW")
procDrawMenuBar = moduser32.NewProc("DrawMenuBar")
procTrackPopupMenuEx = moduser32.NewProc("TrackPopupMenuEx")
procTrackPopupMenu = moduser32.NewProc("TrackPopupMenu")
)

func SendMessageTimeout(hwnd HWND, msg uint32, wParam, lParam uintptr, fuFlags, uTimeout uint32, lpdwResult uintptr) uintptr {
Expand Down Expand Up @@ -1342,3 +1344,42 @@ func DrawMenuBar(hWnd HWND) (bool, error) {
}
return ret != 0, nil
}

// TrackPopupMenu Displays a shortcut menu at the specified location and tracks the selection of items on the menu.
// The shortcut menu can appear anywhere on the screen.
//
// TPM_RETURNCMD is not supported, dont use this flag
// See https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-trackpopupmenu
func TrackPopupMenu(hMenu HMENU, uFlags uint32, x int, y int, nReserved int, hWnd HWND, prcRect *RECT) (bool, error) {
ret, _, err := procTrackPopupMenu.Call(
uintptr(hMenu),
uintptr(uFlags),
uintptr(x),
uintptr(y),
uintptr(nReserved),
uintptr(hWnd),
uintptr(unsafe.Pointer(prcRect)),
)
if !IsErrSuccess(err) {
return false, err
}
return ret != 0, nil
}

// TrackPopupMenuEx 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.
// See https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-trackpopupmenuex
func TrackPopupMenuEx(hMenu HMENU, uFlags uint32, x int, y int, hWnd HWND, lptpm *TPMPARAMS) (bool, error) {
ret, _, err := procTrackPopupMenuEx.Call(
uintptr(hMenu),
uintptr(uFlags),
uintptr(x),
uintptr(y),
uintptr(hWnd),
uintptr(unsafe.Pointer(lptpm)),
)
if !IsErrSuccess(err) {
return false, err
}
return ret != 0, nil
}

0 comments on commit e6eb110

Please sign in to comment.