Skip to content

Commit ce1f5c8

Browse files
authored
Fix the issue of menu click failure caused by excessive menu updates (#77)
1. make the menu identifier never greater than 0xFFFF due to the WM_COMMAND message only provides an unsigned 16-bit integer menu identifier. ref: https://learn.microsoft.com/en-us/windows/win32/menurc/wm-command 2. old menu items are never reused, should delete by DeleteMenu() instead of RemoveMenu(), DeleteMenu() destroys the handle to the menu or submenu and frees the memory. ref: https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-deletemenu https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-removemenu
1 parent 2704a97 commit ce1f5c8

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

src/menu.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ static int append_menu(HMENU hmenu, UINT fMask, UINT fType, UINT fState,
1414
mii.cbSize = sizeof(mii);
1515
mii.fMask = MIIM_ID | fMask;
1616
mii.wID = id++;
17+
// menu identifier should never be greater than the max value of unsigned 16-bit integer
18+
if (id > 0xFFFF) id = WM_USER + 100;
1719

1820
if (fMask & MIIM_FTYPE) mii.fType = fType;
1921
if (fMask & MIIM_STATE) mii.fState = fState;
@@ -141,7 +143,7 @@ static void build_menu(void *talloc_ctx, HMENU hmenu, mpv_node *node) {
141143
// update HMENU if menu node changed
142144
void update_menu(plugin_ctx *ctx, mpv_node *node) {
143145
while (GetMenuItemCount(ctx->hmenu) > 0)
144-
RemoveMenu(ctx->hmenu, 0, MF_BYPOSITION);
146+
DeleteMenu(ctx->hmenu, 0, MF_BYPOSITION);
145147
talloc_free_children(ctx->hmenu_ctx);
146148
build_menu(ctx->hmenu_ctx, ctx->hmenu, node);
147149
}

src/plugin.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
2727
if (GetCursorPos(&pt)) show_menu(ctx, &pt);
2828
break;
2929
case WM_COMMAND:
30+
// low-word of wParam represents the menu identifier, is an unsigned 16-bit integer
3031
handle_menu(ctx, LOWORD(wParam));
3132
break;
3233
default:

0 commit comments

Comments
 (0)