From 874b82f49f8b61f20dab8726947596fdf79c24df Mon Sep 17 00:00:00 2001 From: Valentin Radu Date: Mon, 14 Feb 2022 02:42:57 +0200 Subject: [PATCH] Utility: Implemented "Please wait" pop-up --- ExplorerPatcher/utility.c | 68 +++++++++++++++++++++++++++++++++++++++ ExplorerPatcher/utility.h | 9 ++++++ 2 files changed, 77 insertions(+) diff --git a/ExplorerPatcher/utility.c b/ExplorerPatcher/utility.c index 82f43e7..9a0f9c0 100644 --- a/ExplorerPatcher/utility.c +++ b/ExplorerPatcher/utility.c @@ -1210,4 +1210,72 @@ HRESULT InputBox(BOOL bPassword, HWND hWnd, LPCWSTR wszPrompt, LPCWSTR wszTitle, } return hr; +} + +UINT PleaseWaitTimeout = 0; +HHOOK PleaseWaitHook = NULL; +HWND PleaseWaitHWND = NULL; +void* PleaseWaitCallbackData = NULL; +BOOL (*PleaseWaitCallbackFunc)(void* data) = NULL; +BOOL PleaseWait_UpdateTimeout(int timeout) +{ + if (PleaseWaitHWND) + { + KillTimer(PleaseWaitHWND, 'EPPW'); + PleaseWaitTimeout = timeout; + return SetTimer(PleaseWaitHWND, 'EPPW', PleaseWaitTimeout, PleaseWait_TimerProc); + } + return FALSE; +} + +VOID CALLBACK PleaseWait_TimerProc(HWND hWnd, UINT uMsg, UINT idEvent, DWORD dwTime) +{ + if (idEvent == 'EPPW') + { + if (PleaseWaitCallbackFunc) + { + if (PleaseWaitCallbackFunc(PleaseWaitCallbackData)) + { + return; + } + PleaseWaitCallbackData = NULL; + PleaseWaitCallbackFunc = NULL; + } + KillTimer(hWnd, 'EPPW'); + SetTimer(hWnd, 'EPPW', 0, NULL); // <- this closes the message box + PleaseWaitHWND = NULL; + PleaseWaitTimeout = 0; + } +} + +LRESULT CALLBACK PleaseWait_HookProc(int code, WPARAM wParam, LPARAM lParam) +{ + if (code < 0) + { + return CallNextHookEx(NULL, code, wParam, lParam); + } + + CWPSTRUCT* msg = (CWPSTRUCT*)lParam; + /*if (msg->message == WM_CREATE) + { + CREATESTRUCT* pCS = (CREATESTRUCT*)msg->lParam; + if (pCS->lpszClass == RegisterWindowMessageW(L"Button")) + { + } + }*/ + LRESULT result = CallNextHookEx(NULL, code, wParam, lParam); + + if (msg->message == WM_INITDIALOG) + { + PleaseWaitHWND = msg->hwnd; + LONG_PTR style = GetWindowLongPtrW(PleaseWaitHWND, GWL_STYLE); + SetWindowLongPtrW(PleaseWaitHWND, GWL_STYLE, style & ~WS_SYSMENU); + RECT rc; + GetWindowRect(PleaseWaitHWND, &rc); + SetWindowPos(PleaseWaitHWND, NULL, 0, 0, rc.right - rc.left, rc.bottom - rc.top - MulDiv(50, GetDpiForWindow(PleaseWaitHWND), 96), SWP_NOMOVE | SWP_FRAMECHANGED); + SetTimer(PleaseWaitHWND, 'EPPW', PleaseWaitTimeout, PleaseWait_TimerProc); + UnhookWindowsHookEx(PleaseWaitHook); + PleaseWaitHook = NULL; + } + return result; } \ No newline at end of file diff --git a/ExplorerPatcher/utility.h b/ExplorerPatcher/utility.h index a9a77da..a8bcdec 100644 --- a/ExplorerPatcher/utility.h +++ b/ExplorerPatcher/utility.h @@ -553,4 +553,13 @@ inline BOOL WINAPI PatchContextMenuOfNewMicrosoftIME(BOOL* bFound) } return TRUE; } + +extern UINT PleaseWaitTimeout; +extern HHOOK PleaseWaitHook; +extern HWND PleaseWaitHWND; +extern void* PleaseWaitCallbackData; +extern BOOL (*PleaseWaitCallbackFunc)(void* data); +BOOL PleaseWait_UpdateTimeout(int timeout); +VOID CALLBACK PleaseWait_TimerProc(HWND hWnd, UINT uMsg, UINT idEvent, DWORD dwTime); +LRESULT CALLBACK PleaseWait_HookProc(int code, WPARAM wParam, LPARAM lParam); #endif