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] RegisterWindowMessageW
Browse files Browse the repository at this point in the history
  • Loading branch information
ergoz committed Aug 11, 2019
1 parent fbca7ca commit 157b6d9
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions user32.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ var (
procCreateMenu = moduser32.NewProc("CreateMenu")
procDestroyMenu = moduser32.NewProc("DestroyMenu")
procGetSubMenu = moduser32.NewProc("GetSubMenu")
procRegisterWindowMessageW = moduser32.NewProc("RegisterWindowMessageW")
)

func SendMessageTimeout(hwnd HWND, msg uint32, wParam, lParam uintptr, fuFlags, uTimeout uint32, lpdwResult uintptr) uintptr {
Expand Down Expand Up @@ -1318,20 +1319,36 @@ func CreateMenu() (HMENU, error) {

// 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(uintptr(menu))
func DestroyMenu(hMenu HMENU) (bool, error) {
ret, _, err := procDestroyMenu.Call(uintptr(hMenu))
if ret == 0 && err.(syscall.Errno) != ERROR_SUCCESS {
return false, err
}
return ret != 0, nil
}

// GetSubMenu Retrieves a handle to the drop-down menu or submenu activated by the specified menu item.
// hMenu - A handle to the menu.
// nPos - The zero-based relative position in the specified menu of an item that activates a drop-down menu or submenu.
// return value - If the function succeeds, the return value is a handle to the drop-down menu or submenu activated by
// the menu item. If the menu item does not activate a drop-down menu or submenu, the return value is NULL.
// See https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getsubmenu
func GetSubMenu(menu HMENU, nPos int) (HMENU, error) {
ret, _, err := procGetSubMenu.Call(uintptr(menu), uintptr(nPos))
func GetSubMenu(hMenu HMENU, nPos int) (HMENU, error) {
ret, _, err := procGetSubMenu.Call(uintptr(hMenu), uintptr(nPos))
if ret == 0 && err.(syscall.Errno) != ERROR_SUCCESS {
return HMENU(nil), err
}
return HMENU(ret), nil
}

// RegisterWindowMessageW Defines a new window message that is guaranteed to be unique throughout the system.
// The message value can be used when sending or posting messages.
// lpString - The message to be registered.
// See https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-registerwindowmessagew
func RegisterWindowMessageW(lpString string) (bool, error) {
ret, _, err := procRegisterWindowMessageW.Call(uintptr(pointerStringWithoutError(lpString)))
if ret == 0 && err.(syscall.Errno) != ERROR_SUCCESS {
return false, err
}
return ret != 0, nil
}

0 comments on commit 157b6d9

Please sign in to comment.