Skip to content

Commit

Permalink
add system menu to floating bar in fullscreen mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Marc-André Moreau authored and awakecoding committed Aug 7, 2024
1 parent 1a5975c commit fad3814
Showing 1 changed file with 48 additions and 4 deletions.
52 changes: 48 additions & 4 deletions dll/ApiHooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -518,25 +520,62 @@ 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);
}
}
}
}

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;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
Expand Down

0 comments on commit fad3814

Please sign in to comment.