From ea0ab4570a39989a1f0146e0933fbaa48add3546 Mon Sep 17 00:00:00 2001 From: love-code-yeyixiao <188240888@qq.com> Date: Mon, 5 Aug 2024 10:46:14 +0800 Subject: [PATCH 01/11] AlwaysActive --- Sandboxie/core/dll/gui.c | 13 +++++++++++++ Sandboxie/core/dll/gui_p.h | 6 +++++- Sandboxie/core/dll/guimisc.c | 24 ++++++++++++++++++++++++ 3 files changed, 42 insertions(+), 1 deletion(-) diff --git a/Sandboxie/core/dll/gui.c b/Sandboxie/core/dll/gui.c index 355a0a8aeb..62bb146bff 100644 --- a/Sandboxie/core/dll/gui.c +++ b/Sandboxie/core/dll/gui.c @@ -1668,6 +1668,19 @@ _FX LRESULT Gui_WindowProcW( return TRUE; } + if (uMsg == WM_KILLFOCUS) { + if (SbieApi_QueryConfBool(NULL, L"AlwaysActive", FALSE)) + return NULL; + } + if (uMsg == WM_ACTIVATE) { + if (SbieApi_QueryConfBool(NULL, L"AlwaysActive", FALSE)) + if (wParam == WA_INACTIVE) + return 0; + else { + Gui_PervousActivedWindow == (HWND)hWnd; + } + } + wndproc = __sys_GetPropW(hWnd, (LPCWSTR)Gui_WindowProcOldW_Atom); if (DLL_IMAGE_OFFICE_EXCEL == Dll_ImageType) { diff --git a/Sandboxie/core/dll/gui_p.h b/Sandboxie/core/dll/gui_p.h index a3db5cbd1a..0f53d0023a 100644 --- a/Sandboxie/core/dll/gui_p.h +++ b/Sandboxie/core/dll/gui_p.h @@ -467,6 +467,8 @@ typedef BOOL (*P_SwitchDesktop)(HDESK hDesktop); typedef BOOL (*P_UserHandleGrantAccess)( HANDLE hUserHandle, HANDLE hJob, BOOL bGrant); +typedef HWND (*P_GetActiveWindow)(); + //--------------------------------------------------------------------------- typedef HMONITOR (*P_MonitorFromWindow)(HWND hWnd, DWORD dwFlags); @@ -519,7 +521,7 @@ extern WCHAR* Gui_BoxNameTitleW; extern ATOM Gui_DropTargetProp_Atom; extern ATOM Gui_WindowProcOldW_Atom; extern ATOM Gui_WindowProcOldA_Atom; - +extern HWND Gui_PervousActivedWindow = NULL; //--------------------------------------------------------------------------- // Undo Unicode defines from windows.h @@ -634,6 +636,8 @@ GUI_SYS_VAR(GetWindowRect) GUI_SYS_VAR(GetForegroundWindow) GUI_SYS_VAR(SetForegroundWindow) +GUI_SYS_VAR(GetActiveWindow) + GUI_SYS_VAR(MonitorFromWindow) GUI_SYS_VAR_2(DdeInitialize) diff --git a/Sandboxie/core/dll/guimisc.c b/Sandboxie/core/dll/guimisc.c index b42b34f49d..25b5e73451 100644 --- a/Sandboxie/core/dll/guimisc.c +++ b/Sandboxie/core/dll/guimisc.c @@ -59,6 +59,10 @@ static BOOL Gui_BlockInput(BOOL fBlockIt); static UINT Gui_SendInput(ULONG nInputs, LPINPUT pInputs, ULONG cbInput); +static HWND Gui_GetActiveWindow(); + +static HWND Gui_GetForegroundWindow(); + static HDESK Gui_OpenInputDesktop( DWORD dwFlags, BOOL fInherit, ACCESS_MASK dwDesiredAccess); @@ -208,6 +212,11 @@ _FX BOOLEAN Gui_InitMisc(HMODULE module) SBIEDLL_HOOK_GUI(BringWindowToTop); SBIEDLL_HOOK_GUI(SwitchToThisWindow); SBIEDLL_HOOK_GUI(SetActiveWindow); + + if (SbieApi_QueryConfBool(NULL, L"AlwaysActive", FALSE)) { + SBIEDLL_HOOK_GUI(GetForegroundWindow); + SBIEDLL_HOOK_GUI(GetActiveWindow); + } if (Gui_UseBlockCapture) { SBIEDLL_HOOK_GUI(GetWindowDC); @@ -1707,3 +1716,18 @@ _FX void Gui_SwitchToThisWindow(HWND hWnd, BOOL fAlt) return; __sys_SwitchToThisWindow(hWnd, fAlt); } + +//--------------------------------------------------------------------------- +//Gui_GetActiveiWindow +//--------------------------------------------------------------------------- +static HWND Gui_GetActiveWindow() { + if (SbieApi_QueryConfBool(NULL, L"AlwaysActive", FALSE)) + return (Gui_PervousActivedWindow == NULL ? __sys_GetActiveWindow() : Gui_PervousActivedWindow); + return __sys_GetActiveWindow(); +} + +static HWND Gui_GetForegroundWindow() { + if (SbieApi_QueryConfBool(NULL, L"AlwaysActive", FALSE)) + return (Gui_PervousActivedWindow == NULL ? __sys_GetActiveWindow() : Gui_PervousActivedWindow); + return __sys_GetActiveWindow(); +} From 1a919703388272a3d1387d691019128da4ece47f Mon Sep 17 00:00:00 2001 From: love-code-yeyixiao <188240888@qq.com> Date: Mon, 5 Aug 2024 15:21:07 +0800 Subject: [PATCH 02/11] fix --- Sandboxie/core/dll/gui.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sandboxie/core/dll/gui.c b/Sandboxie/core/dll/gui.c index 62bb146bff..d21ca9b034 100644 --- a/Sandboxie/core/dll/gui.c +++ b/Sandboxie/core/dll/gui.c @@ -1677,7 +1677,7 @@ _FX LRESULT Gui_WindowProcW( if (wParam == WA_INACTIVE) return 0; else { - Gui_PervousActivedWindow == (HWND)hWnd; + Gui_PervousActivedWindow = (HWND)hWnd; } } From 6d6f65afdeb4af4b54219a66466abe93721e854e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=88=B1=E7=BC=96=E7=A8=8B=E7=9A=84=E5=8F=B6=E4=B8=80?= =?UTF-8?q?=E7=AC=91?= <92030377+love-code-yeyixiao@users.noreply.github.com> Date: Mon, 5 Aug 2024 16:20:46 +0800 Subject: [PATCH 03/11] Update Sandboxie/core/dll/gui.c Co-authored-by: offhub <6871698+offhub@users.noreply.github.com> --- Sandboxie/core/dll/gui.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sandboxie/core/dll/gui.c b/Sandboxie/core/dll/gui.c index d21ca9b034..9811889591 100644 --- a/Sandboxie/core/dll/gui.c +++ b/Sandboxie/core/dll/gui.c @@ -1677,7 +1677,7 @@ _FX LRESULT Gui_WindowProcW( if (wParam == WA_INACTIVE) return 0; else { - Gui_PervousActivedWindow = (HWND)hWnd; + Gui_PreviousActiveWindow = (HWND)hWnd; } } From 8d8ba718a8ab09d2d516e304965571902c3fc56d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=88=B1=E7=BC=96=E7=A8=8B=E7=9A=84=E5=8F=B6=E4=B8=80?= =?UTF-8?q?=E7=AC=91?= <92030377+love-code-yeyixiao@users.noreply.github.com> Date: Mon, 5 Aug 2024 16:20:55 +0800 Subject: [PATCH 04/11] Update Sandboxie/core/dll/gui_p.h Co-authored-by: offhub <6871698+offhub@users.noreply.github.com> --- Sandboxie/core/dll/gui_p.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sandboxie/core/dll/gui_p.h b/Sandboxie/core/dll/gui_p.h index 0f53d0023a..9bc81467a9 100644 --- a/Sandboxie/core/dll/gui_p.h +++ b/Sandboxie/core/dll/gui_p.h @@ -521,7 +521,7 @@ extern WCHAR* Gui_BoxNameTitleW; extern ATOM Gui_DropTargetProp_Atom; extern ATOM Gui_WindowProcOldW_Atom; extern ATOM Gui_WindowProcOldA_Atom; -extern HWND Gui_PervousActivedWindow = NULL; +extern HWND Gui_PreviousActiveWindow = NULL; //--------------------------------------------------------------------------- // Undo Unicode defines from windows.h From 730ab2248f39fa0ff613907258f1dae16e46eaad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=88=B1=E7=BC=96=E7=A8=8B=E7=9A=84=E5=8F=B6=E4=B8=80?= =?UTF-8?q?=E7=AC=91?= <92030377+love-code-yeyixiao@users.noreply.github.com> Date: Mon, 5 Aug 2024 16:21:05 +0800 Subject: [PATCH 05/11] Update Sandboxie/core/dll/guimisc.c Co-authored-by: offhub <6871698+offhub@users.noreply.github.com> --- Sandboxie/core/dll/guimisc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sandboxie/core/dll/guimisc.c b/Sandboxie/core/dll/guimisc.c index 25b5e73451..c823cddcc7 100644 --- a/Sandboxie/core/dll/guimisc.c +++ b/Sandboxie/core/dll/guimisc.c @@ -1722,7 +1722,7 @@ _FX void Gui_SwitchToThisWindow(HWND hWnd, BOOL fAlt) //--------------------------------------------------------------------------- static HWND Gui_GetActiveWindow() { if (SbieApi_QueryConfBool(NULL, L"AlwaysActive", FALSE)) - return (Gui_PervousActivedWindow == NULL ? __sys_GetActiveWindow() : Gui_PervousActivedWindow); + return (Gui_PreviousActiveWindow == NULL ? __sys_GetActiveWindow() : Gui_PreviousActiveWindow); return __sys_GetActiveWindow(); } From 06842d30d022ce45670c5dcabe94ce06ee5cc904 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=88=B1=E7=BC=96=E7=A8=8B=E7=9A=84=E5=8F=B6=E4=B8=80?= =?UTF-8?q?=E7=AC=91?= <92030377+love-code-yeyixiao@users.noreply.github.com> Date: Mon, 5 Aug 2024 16:21:13 +0800 Subject: [PATCH 06/11] Update Sandboxie/core/dll/guimisc.c Co-authored-by: offhub <6871698+offhub@users.noreply.github.com> --- Sandboxie/core/dll/guimisc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sandboxie/core/dll/guimisc.c b/Sandboxie/core/dll/guimisc.c index c823cddcc7..a0570ccf2c 100644 --- a/Sandboxie/core/dll/guimisc.c +++ b/Sandboxie/core/dll/guimisc.c @@ -1728,6 +1728,6 @@ static HWND Gui_GetActiveWindow() { static HWND Gui_GetForegroundWindow() { if (SbieApi_QueryConfBool(NULL, L"AlwaysActive", FALSE)) - return (Gui_PervousActivedWindow == NULL ? __sys_GetActiveWindow() : Gui_PervousActivedWindow); + return (Gui_PreviousActiveWindow == NULL ? __sys_GetActiveWindow() : Gui_PreviousActiveWindow); return __sys_GetActiveWindow(); } From d76054056db396f10cecfca57d385bfee28577d7 Mon Sep 17 00:00:00 2001 From: love-code-yeyixiao <188240888@qq.com> Date: Mon, 5 Aug 2024 17:03:30 +0800 Subject: [PATCH 07/11] fix --- Sandboxie/core/dll/gui_p.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Sandboxie/core/dll/gui_p.h b/Sandboxie/core/dll/gui_p.h index 0f53d0023a..1bf6e538f5 100644 --- a/Sandboxie/core/dll/gui_p.h +++ b/Sandboxie/core/dll/gui_p.h @@ -521,7 +521,10 @@ extern WCHAR* Gui_BoxNameTitleW; extern ATOM Gui_DropTargetProp_Atom; extern ATOM Gui_WindowProcOldW_Atom; extern ATOM Gui_WindowProcOldA_Atom; +#ifndef PervousActivedWindow +#define PervousActivedWindow extern HWND Gui_PervousActivedWindow = NULL; +#endif // !PervousActivedWindow //--------------------------------------------------------------------------- // Undo Unicode defines from windows.h From 648fd472850314a119e97bbcafd3a639fff01801 Mon Sep 17 00:00:00 2001 From: love-code-yeyixiao <188240888@qq.com> Date: Mon, 5 Aug 2024 17:12:49 +0800 Subject: [PATCH 08/11] fix --- Sandboxie/core/dll/gui_p.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Sandboxie/core/dll/gui_p.h b/Sandboxie/core/dll/gui_p.h index 68f1f9ebb2..fa956a4636 100644 --- a/Sandboxie/core/dll/gui_p.h +++ b/Sandboxie/core/dll/gui_p.h @@ -521,10 +521,10 @@ extern WCHAR* Gui_BoxNameTitleW; extern ATOM Gui_DropTargetProp_Atom; extern ATOM Gui_WindowProcOldW_Atom; extern ATOM Gui_WindowProcOldA_Atom; -#ifndef PreviousActivedWindow -#define PreviousActivedWindow -extern HWND Gui_PreviousActivedWindow = NULL; -#endif // !PreviousActivedWindow +#ifndef PreviousActiveWindow +#define PreviousActiveWindow +extern HWND Gui_PreviousActiveWindow = NULL; +#endif // !PreviousActiveWindow //--------------------------------------------------------------------------- // Undo Unicode defines from windows.h From 1f54a3a906695f2181fd02a9a9337b9fa8907e38 Mon Sep 17 00:00:00 2001 From: love-code-yeyixiao <188240888@qq.com> Date: Mon, 5 Aug 2024 17:19:06 +0800 Subject: [PATCH 09/11] Fix --- Sandboxie/core/dll/gui.c | 2 +- Sandboxie/core/dll/gui_p.h | 5 +---- Sandboxie/core/dll/guimisc.c | 3 ++- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/Sandboxie/core/dll/gui.c b/Sandboxie/core/dll/gui.c index 9811889591..a3ac02a153 100644 --- a/Sandboxie/core/dll/gui.c +++ b/Sandboxie/core/dll/gui.c @@ -1641,7 +1641,7 @@ _FX VOID Gui_ProtectScreen(HWND hWnd) // Gui_WindowProcW //--------------------------------------------------------------------------- - +static HWND Gui_PreviousActiveWindow = NULL; _FX LRESULT Gui_WindowProcW( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { diff --git a/Sandboxie/core/dll/gui_p.h b/Sandboxie/core/dll/gui_p.h index fa956a4636..5e73764019 100644 --- a/Sandboxie/core/dll/gui_p.h +++ b/Sandboxie/core/dll/gui_p.h @@ -521,10 +521,7 @@ extern WCHAR* Gui_BoxNameTitleW; extern ATOM Gui_DropTargetProp_Atom; extern ATOM Gui_WindowProcOldW_Atom; extern ATOM Gui_WindowProcOldA_Atom; -#ifndef PreviousActiveWindow -#define PreviousActiveWindow -extern HWND Gui_PreviousActiveWindow = NULL; -#endif // !PreviousActiveWindow + //--------------------------------------------------------------------------- // Undo Unicode defines from windows.h diff --git a/Sandboxie/core/dll/guimisc.c b/Sandboxie/core/dll/guimisc.c index a0570ccf2c..0d76857f1f 100644 --- a/Sandboxie/core/dll/guimisc.c +++ b/Sandboxie/core/dll/guimisc.c @@ -1718,8 +1718,9 @@ _FX void Gui_SwitchToThisWindow(HWND hWnd, BOOL fAlt) } //--------------------------------------------------------------------------- -//Gui_GetActiveiWindow +//Gui_GetActiveWindow //--------------------------------------------------------------------------- +static HWND Gui_PreviousActiveWindow; static HWND Gui_GetActiveWindow() { if (SbieApi_QueryConfBool(NULL, L"AlwaysActive", FALSE)) return (Gui_PreviousActiveWindow == NULL ? __sys_GetActiveWindow() : Gui_PreviousActiveWindow); From 9299f17d6fcdc352ec448c4405e7c05d0aa6ea06 Mon Sep 17 00:00:00 2001 From: love-code-yeyixiao <188240888@qq.com> Date: Mon, 5 Aug 2024 18:22:54 +0800 Subject: [PATCH 10/11] Fix --- Sandboxie/core/dll/gui.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sandboxie/core/dll/gui.c b/Sandboxie/core/dll/gui.c index a3ac02a153..afb8304a23 100644 --- a/Sandboxie/core/dll/gui.c +++ b/Sandboxie/core/dll/gui.c @@ -1670,7 +1670,7 @@ _FX LRESULT Gui_WindowProcW( if (uMsg == WM_KILLFOCUS) { if (SbieApi_QueryConfBool(NULL, L"AlwaysActive", FALSE)) - return NULL; + return FALSE; } if (uMsg == WM_ACTIVATE) { if (SbieApi_QueryConfBool(NULL, L"AlwaysActive", FALSE)) From 89d813835e5cb4486ee4233a02243c88fba8ccda Mon Sep 17 00:00:00 2001 From: love-code-yeyixiao <188240888@qq.com> Date: Mon, 5 Aug 2024 19:36:11 +0800 Subject: [PATCH 11/11] fix --- Sandboxie/core/dll/gui.c | 20 ++++++++++++++++---- Sandboxie/core/dll/guimisc.c | 4 ++-- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/Sandboxie/core/dll/gui.c b/Sandboxie/core/dll/gui.c index afb8304a23..ad06d3eeb3 100644 --- a/Sandboxie/core/dll/gui.c +++ b/Sandboxie/core/dll/gui.c @@ -1668,10 +1668,10 @@ _FX LRESULT Gui_WindowProcW( return TRUE; } - if (uMsg == WM_KILLFOCUS) { - if (SbieApi_QueryConfBool(NULL, L"AlwaysActive", FALSE)) - return FALSE; - } + //if (uMsg == WM_KILLFOCUS) { + // if (SbieApi_QueryConfBool(NULL, L"AlwaysActive", FALSE)) + // return FALSE; + //} if (uMsg == WM_ACTIVATE) { if (SbieApi_QueryConfBool(NULL, L"AlwaysActive", FALSE)) if (wParam == WA_INACTIVE) @@ -1742,6 +1742,18 @@ _FX LRESULT Gui_WindowProcA( if (SbieApi_QueryConfBool(NULL, L"BlockInterferePower", FALSE)) return TRUE; } + //if (uMsg == WM_KILLFOCUS) { + // if (SbieApi_QueryConfBool(NULL, L"AlwaysActive", FALSE)) + // return FALSE; + //} + if (uMsg == WM_ACTIVATE) { + if (SbieApi_QueryConfBool(NULL, L"AlwaysActive", FALSE)) + if (wParam == WA_INACTIVE) + return 0; + else { + Gui_PreviousActiveWindow = (HWND)hWnd; + } + } wndproc = __sys_GetPropW(hWnd, (LPCWSTR)Gui_WindowProcOldA_Atom); lResult = __sys_CallWindowProcA(wndproc, hWnd, uMsg, wParam, new_lParam); diff --git a/Sandboxie/core/dll/guimisc.c b/Sandboxie/core/dll/guimisc.c index 0d76857f1f..d16ebfb5ef 100644 --- a/Sandboxie/core/dll/guimisc.c +++ b/Sandboxie/core/dll/guimisc.c @@ -1722,8 +1722,8 @@ _FX void Gui_SwitchToThisWindow(HWND hWnd, BOOL fAlt) //--------------------------------------------------------------------------- static HWND Gui_PreviousActiveWindow; static HWND Gui_GetActiveWindow() { - if (SbieApi_QueryConfBool(NULL, L"AlwaysActive", FALSE)) - return (Gui_PreviousActiveWindow == NULL ? __sys_GetActiveWindow() : Gui_PreviousActiveWindow); + //if (SbieApi_QueryConfBool(NULL, L"AlwaysActive", FALSE)) + // return (Gui_PreviousActiveWindow == NULL ? __sys_GetActiveWindow() : Gui_PreviousActiveWindow); return __sys_GetActiveWindow(); }