Skip to content

Commit ad91573

Browse files
committed
feat: Enhance AppendMenu function to support both number and HMENU for new item ID
1 parent 7b33b8f commit ad91573

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

source/win32/user32/menu-funcs.ts

+20-3
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,34 @@ export const DestroyMenu: koffi.KoffiFunc<(
4646
hMenu: HMENU
4747
) => number> = user32('DestroyMenu', cBOOL, [ cHMENU ])
4848

49+
50+
const AppendMenuInternalN: koffi.KoffiFunc<(
51+
hMenu: HMENU,
52+
uFlags: MF_ | number,
53+
uIDNewItem: number,
54+
lpNewItem: string | null
55+
) => number> = user32('AppendMenuW', cBOOL, [ cHMENU, cUINT, cUINT, cLPCWSTR ]);
56+
57+
const AppendMenuInternalH: koffi.KoffiFunc<(
58+
hMenu: HMENU,
59+
uFlags: MF_ | number,
60+
uIDNewItem: HMENU,
61+
lpNewItem: string | null
62+
) => number> = user32('AppendMenuW', cBOOL, [ cHMENU, cUINT, cHMENU, cLPCWSTR ]);
4963
/**
5064
* Appends a new item to the end of the specified menu bar, drop-down menu, submenu, or shortcut menu.
5165
*
5266
* https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-appendmenuw
5367
*/
54-
export const AppendMenu: koffi.KoffiFunc<(
68+
export const AppendMenu = (
5569
hMenu: HMENU,
5670
uFlags: MF_ | number,
57-
uIDNewItem: number,
71+
uIDNewItem: number | HMENU,
5872
lpNewItem: string | null
59-
) => number> = user32('AppendMenuW', cBOOL, [ cHMENU, cUINT, cUINT, cLPCWSTR ])
73+
) => {
74+
if (typeof uIDNewItem === 'number') return AppendMenuInternalN(hMenu, uFlags, uIDNewItem, lpNewItem);
75+
return AppendMenuInternalH(hMenu, uFlags, uIDNewItem, lpNewItem);
76+
}
6077

6178
/**
6279
* Sets the checked state of a menu item.

0 commit comments

Comments
 (0)