github.com/AlpineAIO/wails/v2@v2.0.0-beta.32.0.20240505041856-1047a8fa5fef/internal/platform/win32/menu.go (about)

     1  //go:build windows
     2  
     3  package win32
     4  
     5  type Menu HMENU
     6  type PopupMenu Menu
     7  
     8  func CreatePopupMenu() PopupMenu {
     9  	ret, _, _ := procCreatePopupMenu.Call(0, 0, 0, 0)
    10  	return PopupMenu(ret)
    11  }
    12  
    13  func (m Menu) Destroy() bool {
    14  	ret, _, _ := procDestroyMenu.Call(uintptr(m))
    15  	return ret != 0
    16  }
    17  
    18  func (p PopupMenu) Destroy() bool {
    19  	return Menu(p).Destroy()
    20  }
    21  
    22  func (p PopupMenu) Track(flags uint, x, y int, wnd HWND) bool {
    23  	ret, _, _ := procTrackPopupMenu.Call(
    24  		uintptr(p),
    25  		uintptr(flags),
    26  		uintptr(x),
    27  		uintptr(y),
    28  		0,
    29  		uintptr(wnd),
    30  		0,
    31  	)
    32  	return ret != 0
    33  }
    34  
    35  func (p PopupMenu) Append(flags uintptr, id uintptr, text string) bool {
    36  	return Menu(p).Append(flags, id, text)
    37  }
    38  
    39  func (m Menu) Append(flags uintptr, id uintptr, text string) bool {
    40  	ret, _, _ := procAppendMenuW.Call(
    41  		uintptr(m),
    42  		flags,
    43  		id,
    44  		MustStringToUTF16uintptr(text),
    45  	)
    46  	return ret != 0
    47  }
    48  
    49  func (p PopupMenu) Check(id uintptr, checked bool) bool {
    50  	return Menu(p).Check(id, checked)
    51  }
    52  
    53  func (m Menu) Check(id uintptr, check bool) bool {
    54  	var checkState uint = MF_UNCHECKED
    55  	if check {
    56  		checkState = MF_CHECKED
    57  	}
    58  	return CheckMenuItem(HMENU(m), id, checkState) != 0
    59  }
    60  
    61  func (m Menu) CheckRadio(startID int, endID int, selectedID int) bool {
    62  	ret, _, _ := procCheckMenuRadioItem.Call(
    63  		uintptr(m),
    64  		uintptr(startID),
    65  		uintptr(endID),
    66  		uintptr(selectedID),
    67  		MF_BYCOMMAND)
    68  	return ret != 0
    69  }
    70  
    71  func CheckMenuItem(menu HMENU, id uintptr, flags uint) uint {
    72  	ret, _, _ := procCheckMenuItem.Call(
    73  		uintptr(menu),
    74  		id,
    75  		uintptr(flags),
    76  	)
    77  	return uint(ret)
    78  }
    79  
    80  func (p PopupMenu) CheckRadio(startID, endID, selectedID int) bool {
    81  	return Menu(p).CheckRadio(startID, endID, selectedID)
    82  }