From fad3814ff8612fade20884ba4c222dffdf188506 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Moreau?= Date: Wed, 7 Aug 2024 14:40:34 -0400 Subject: [PATCH] add system menu to floating bar in fullscreen mode --- dll/ApiHooks.cpp | 52 ++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 48 insertions(+), 4 deletions(-) diff --git a/dll/ApiHooks.cpp b/dll/ApiHooks.cpp index be74abf..d36824e 100644 --- a/dll/ApiHooks.cpp +++ b/dll/ApiHooks.cpp @@ -510,6 +510,8 @@ BOOL Hook_StretchBlt( static WNDPROC Real_TscShellContainerWndProc = NULL; +static HWND g_hTscShellContainerWnd = NULL; + LRESULT CALLBACK Hook_TscShellContainerWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { LRESULT result; @@ -518,18 +520,29 @@ LRESULT CALLBACK Hook_TscShellContainerWndProc(HWND hWnd, UINT uMsg, WPARAM wPar //MsRdpEx_LogPrint(DEBUG, "TscShellContainerWnd: %s (%d)", MsRdpEx_GetWindowMessageName(uMsg), uMsg); + if (uMsg == WM_COMMAND) + uMsg = WM_SYSCOMMAND; // TrackPopupMenu sends WM_COMMAND instead of WM_SYSCOMMAND + result = Real_TscShellContainerWndProc(hWnd, uMsg, wParam, lParam); + if (uMsg == WM_NCCREATE) + { + g_hTscShellContainerWnd = hWnd; + } + if (instance) { HWND hInputCaptureWnd = 0; ((IMsRdpExInstance*)instance)->GetInputWindow(&hInputCaptureWnd); - if ((uMsg == WM_SYSCOMMAND) && hInputCaptureWnd) + if (hInputCaptureWnd) { - if ((wParam >= SYSMENU_RDP_RANGE_FIRST_ID) && (wParam <= SYSMENU_RDP_RANGE_LAST_ID)) { - SendMessage(hInputCaptureWnd, uMsg, wParam, lParam); + if (uMsg == WM_SYSCOMMAND) + { + if ((wParam >= SYSMENU_RDP_RANGE_FIRST_ID) && (wParam <= SYSMENU_RDP_RANGE_LAST_ID)) { + SendMessage(hInputCaptureWnd, WM_SYSCOMMAND, wParam, lParam); + } } } } @@ -537,6 +550,32 @@ LRESULT CALLBACK Hook_TscShellContainerWndProc(HWND hWnd, UINT uMsg, WPARAM wPar return result; } +static WNDPROC Real_BBarWndProc = NULL; + +static HMENU g_hExtraMenu = NULL; + +LRESULT CALLBACK Hook_BBarWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) +{ + LRESULT result; + + //MsRdpEx_LogPrint(DEBUG, "BBarWnd: %s (%d)", MsRdpEx_GetWindowMessageName(uMsg), uMsg); + + result = Real_BBarWndProc(hWnd, uMsg, wParam, lParam); + + if (uMsg == WM_CONTEXTMENU) + { + if (g_hExtraMenu && g_hTscShellContainerWnd) + { + int xPos = GET_X_LPARAM(lParam); + int yPos = GET_Y_LPARAM(lParam); + HMENU hSystemMenu = GetSystemMenu(g_hTscShellContainerWnd, FALSE); + TrackPopupMenu(hSystemMenu, TPM_RIGHTBUTTON, xPos, yPos, 0, g_hTscShellContainerWnd, NULL); + } + } + + return result; +} + static WNDPROC Real_OPWndProc_mstscax = NULL; static WNDPROC Real_OPWndProc_rdclientax = NULL; @@ -618,9 +657,12 @@ ATOM Hook_RegisterClassExW(WNDCLASSEXW* wndClass) if (MsRdpEx_StringEquals(lpClassNameA, "TscShellContainerClass")) { Real_TscShellContainerWndProc = wndClass->lpfnWndProc; - wndClass->lpszClassName = L"TscShellContainerClass"; wndClass->lpfnWndProc = Hook_TscShellContainerWndProc; } + else if (MsRdpEx_StringEquals(lpClassNameA, "BBarWindowClass")) { + Real_BBarWndProc = wndClass->lpfnWndProc; + wndClass->lpfnWndProc = Hook_BBarWndProc; + } else if (MsRdpEx_StringEquals(lpClassNameA, "OPWindowClass")) { if (MsRdpEx_IsAddressInRdclientAxModule(_ReturnAddress())) { Real_OPWndProc_rdclientax = wndClass->lpfnWndProc; @@ -728,6 +770,8 @@ LRESULT CALLBACK Hook_IHWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lPar AppendMenu(hSystemMenu, MF_SEPARATOR, 0, NULL); AppendMenu(hSystemMenu, MF_POPUP, (::UINT_PTR)hExtraMenu, L"Extra"); + g_hExtraMenu = hExtraMenu; + instance->AttachTscShellContainerWindow(hParentWnd); } }