@@ -8,12 +8,56 @@ import (
88 "github.com/whtiehack/wingui/winapi"
99)
1010
11+ /*
12+ Manual menu creation example:
13+
14+ const (
15+ idExit = 60001
16+ idHello = 60002
17+ idToggle = 60003
18+ )
19+
20+ menu := wingui.NewMenu()
21+ fileMenu := wingui.NewPopupMenu()
22+ _ = fileMenu.AppendItem(idExit, "Exit")
23+ _ = menu.AppendSubMenu(fileMenu, "File")
24+
25+ demoMenu := wingui.NewPopupMenu()
26+ _ = demoMenu.AppendItem(idHello, "Hello MessageBox")
27+ _ = demoMenu.AppendItem(idToggle, "Toggle Checked")
28+ _ = menu.AppendSubMenu(demoMenu, "Demo")
29+
30+ _ = dlg.SetMenu(menu)
31+
32+ checked := false
33+ dlg.OnCommand = func(id uint16) {
34+ switch id {
35+ case idExit:
36+ dlg.Close()
37+ case idHello:
38+ wingui.MessageBox(dlg.Handle(), "Hello from Menu", "Menu", win.MB_OK|win.MB_ICONINFORMATION)
39+ case idToggle:
40+ checked = !checked
41+ demoMenu.CheckItem(idToggle, checked)
42+ }
43+ }
44+ */
45+
1146// Menu wraps a Win32 HMENU.
1247type Menu struct {
1348 hMenu win.HMENU
1449 count uint32
1550}
1651
52+ // NewMenuFromResource loads a menu resource by id (from the module hInstance).
53+ func NewMenuFromResource (id uintptr ) * Menu {
54+ h := win .LoadMenu (hInstance , win .MAKEINTRESOURCE (id ))
55+ if h == 0 {
56+ return nil
57+ }
58+ return & Menu {hMenu : h }
59+ }
60+
1761// Handle returns the underlying HMENU.
1862func (m * Menu ) Handle () win.HMENU {
1963 if m == nil {
@@ -22,6 +66,18 @@ func (m *Menu) Handle() win.HMENU {
2266 return m .hMenu
2367}
2468
69+ // SubMenu returns the submenu at the given position (0-based), or nil.
70+ func (m * Menu ) SubMenu (pos int32 ) * Menu {
71+ if m == nil || m .hMenu == 0 {
72+ return nil
73+ }
74+ h := winapi .GetSubMenu (m .hMenu , pos )
75+ if h == 0 {
76+ return nil
77+ }
78+ return & Menu {hMenu : h }
79+ }
80+
2581// Destroy releases the underlying HMENU.
2682func (m * Menu ) Destroy () bool {
2783 if m == nil || m .hMenu == 0 {
0 commit comments