@@ -31,8 +31,7 @@ mb_shell::track_popup_menu(mb_shell::menu menu, int x, int y,
3131 set_thread_name (" breeze::context_menu_renderer" );
3232 perf_counter perf (" mb_shell::track_popup_menu" );
3333
34- bool shift_pressed =
35- (GetKeyState (VK_SHIFT) & 0x8000 ) != 0 ;
34+ bool shift_pressed = (GetKeyState (VK_SHIFT) & 0x8000 ) != 0 ;
3635
3736 auto menu_render = menu_render::create (x, y, menu, run_js);
3837 menu_render.rt ->last_time = menu_render.rt ->clock .now ();
@@ -78,7 +77,6 @@ mb_shell::track_popup_menu(mb_shell::menu menu, int x, int y,
7877 qjs::wait_with_msgloop ([&]() { selected_menu_future.wait (); });
7978
8079 auto selected_menu = selected_menu_future.get ();
81- mb_shell::context_menu_hooks::block_js_reload.fetch_sub (1 );
8280
8381 return selected_menu;
8482}
@@ -112,7 +110,7 @@ void mb_shell::context_menu_hooks::install_common_hook() {
112110 PostMessageW (hWnd, WM_COMMAND, *selected_menu, 0 );
113111 PostMessageW (hWnd, WM_NULL, 0 , 0 );
114112 }
115-
113+ mb_shell::context_menu_hooks::block_js_reload. fetch_sub ( 1 );
116114 return (int32_t )selected_menu.value_or (0 );
117115 });
118116}
@@ -224,40 +222,46 @@ void mb_shell::context_menu_hooks::install_SHCreateDefaultContextMenu_hook() {
224222 auto res = SHCreateDefaultContextMenu (def, riid, ppv);
225223 SHCreateDefaultContextMenuHook->install ();
226224
227- IContextMenu *pdcm = (IContextMenu *)*ppv;
225+ IContextMenu *pdcm = (IContextMenu *)( *ppv) ;
228226 if (SUCCEEDED (res) && pdcm) {
229- IContextMenu2 *pcm2 = NULL ;
230-
231- int pcmType = 0 ;
232- UpgradeContextMenu (pdcm, reinterpret_cast <void **>(&pcm2),
233- &pcmType);
234-
235- IContextMenu *pCM (pcm2);
227+ CComPtr<IContextMenu> pCM (pdcm);
236228
237229 HMENU hmenu = CreatePopupMenu ();
238230 pCM->QueryContextMenu (hmenu, 0 , 1 , 0x7FFF ,
239231 CMF_EXPLORE | CMF_CANRENAME);
240232
241- POINT pt;
242- GetCursorPos (&pt);
243-
244- int res = TrackPopupMenuEx (
245- hmenu, TPM_LEFTALIGN | TPM_RIGHTBUTTON | TPM_RETURNCMD,
246- pt.x , pt.y , def->hwnd , NULL );
247-
248- if (res > 0 ) {
249- CMINVOKECOMMANDINFOEX ici = {};
250- ici.cbSize = sizeof (CMINVOKECOMMANDINFOEX);
251- ici.hwnd = def->hwnd ;
252- ici.fMask = 0x100000 ; /* CMIC_MASK_UNICODE */
253- ici.lpVerb = MAKEINTRESOURCEA (res - 1 );
254- ici.lpVerbW = MAKEINTRESOURCEW (res - 1 );
255- ici.nShow = SW_SHOWNORMAL;
233+ CComPtr<IContextMenu2> pCM2 = NULL ;
234+ if (SUCCEEDED (pCM->QueryInterface (&pCM2))) {
235+ POINT pt;
236+ GetCursorPos (&pt);
237+ auto hwndOwner = def->hwnd ;
238+ entry::main_window_loop_hook.install (hwndOwner);
239+ block_js_reload.fetch_add (1 );
240+ perf_counter perf (" TrackPopupMenuEx" );
241+ menu menu = menu::construct_with_hmenu (
242+ hmenu, hwndOwner, true ,
243+ [=](int message, WPARAM wParam, LPARAM lParam) {
244+ pCM2->HandleMenuMsg (message, wParam, lParam);
245+ });
246+ perf.end (" construct_with_hmenu" );
247+
248+ auto selected_menu = track_popup_menu (menu, pt.x , pt.y );
249+ mb_shell::context_menu_hooks::block_js_reload.fetch_sub (1 );
250+
251+ if (selected_menu) {
252+ CMINVOKECOMMANDINFOEX ici = {};
253+ ici.cbSize = sizeof (CMINVOKECOMMANDINFOEX);
254+ ici.hwnd = hwndOwner;
255+ ici.fMask = 0x100000 ; /* CMIC_MASK_UNICODE */
256+ ici.lpVerb = MAKEINTRESOURCEA (*selected_menu - 1 );
257+ ici.lpVerbW = MAKEINTRESOURCEW (*selected_menu - 1 );
258+ ici.nShow = SW_SHOWNORMAL;
259+
260+ pCM->InvokeCommand ((LPCMINVOKECOMMANDINFO)&ici);
261+ }
256262
257- pCM-> InvokeCommand ((LPCMINVOKECOMMANDINFO)&ici) ;
263+ close_next_create_window_exw_window = true ;
258264 }
259-
260- close_next_create_window_exw_window = true ;
261265 }
262266
263267 return res;
0 commit comments