From: Vincent Povirk Subject: [5/6] explorer: Make separate thread for start menu. Message-Id: Date: Tue, 10 Dec 2013 15:11:37 -0600 I thought running potentially-blocking operations (like reading shell folders and eventually extracting icons) on the main thread of explorer could be a bad idea. From 7c7f275f6f32a5299ac35956c02deebd2dd49776 Mon Sep 17 00:00:00 2001 From: Vincent Povirk Date: Fri, 6 Dec 2013 15:46:12 -0600 Subject: [PATCH 5/6] explorer: Make separate thread for start menu. --- programs/explorer/startmenu.c | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/programs/explorer/startmenu.c b/programs/explorer/startmenu.c index b0cc702..5730b39 100644 --- a/programs/explorer/startmenu.c +++ b/programs/explorer/startmenu.c @@ -55,6 +55,10 @@ static struct menu_item user_startmenu = {{0}}; static ATOM menu_parent_class; static HWND menu_parent; +DWORD menu_thread_id; + +#define WM_POPUP_MENU WM_USER + static ULONG copy_pidls(struct menu_item* item, LPITEMIDLIST dest) { ULONG item_size; @@ -362,7 +366,7 @@ LRESULT CALLBACK menu_wndproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) return DefWindowProcW(hwnd, msg, wparam, lparam); } -void do_startmenu(HWND hwnd) +void popup_startmenu(HWND hwnd) { LPITEMIDLIST pidl; MENUINFO mi; @@ -445,3 +449,34 @@ void do_startmenu(HWND hwnd) } } +DWORD CALLBACK menu_thread_proc(void* user_data) +{ + HWND parent = user_data; + MSG msg; + + popup_startmenu(parent); + + while(GetMessageW(&msg, NULL, 0, 0) != 0) + { + if (msg.hwnd == NULL && msg.message == WM_POPUP_MENU) + { + popup_startmenu((HWND)msg.lParam); + } + else + { + TranslateMessage(&msg); + DispatchMessageW(&msg); + } + } + + return 0; +} + +void do_startmenu(HWND hwnd) +{ + if (menu_thread_id) + PostThreadMessageW(menu_thread_id, WM_POPUP_MENU, 0, (LPARAM)hwnd); + else + CreateThread(NULL, 0, menu_thread_proc, hwnd, 0, &menu_thread_id); +} + -- 1.8.1.2