Skip to content

Commit

Permalink
add resize to fit window menu option
Browse files Browse the repository at this point in the history
  • Loading branch information
Marc-André Moreau authored and awakecoding committed Aug 12, 2024
1 parent fad3814 commit 3fa24ff
Showing 1 changed file with 50 additions and 1 deletion.
51 changes: 50 additions & 1 deletion dll/ApiHooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,8 @@ BOOL Hook_StretchBlt(
#define SYSMENU_RDP_RANGE_FIRST_ID 7100
#define SYSMENU_RDP_SEND_CTRL_ALT_DEL_ID 7101
#define SYSMENU_RDP_SEND_CTRL_ALT_END_ID 7102
#define SYSMENU_RDP_RANGE_LAST_ID 7103
#define SYSMENU_RDP_RESIZE_TO_FIT_WINDOW_ID 7103
#define SYSMENU_RDP_RANGE_LAST_ID 7104

static WNDPROC Real_TscShellContainerWndProc = NULL;

Expand Down Expand Up @@ -766,6 +767,8 @@ LRESULT CALLBACK Hook_IHWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lPar
HMENU hExtraMenu = CreateMenu();
AppendMenu(hExtraMenu, MF_STRING, SYSMENU_RDP_SEND_CTRL_ALT_DEL_ID, L"Send Ctrl+Alt+Del");
AppendMenu(hExtraMenu, MF_STRING, SYSMENU_RDP_SEND_CTRL_ALT_END_ID, L"Send Ctrl+Alt+End");
AppendMenu(hExtraMenu, MF_SEPARATOR, 0, NULL);
AppendMenu(hExtraMenu, MF_STRING, SYSMENU_RDP_RESIZE_TO_FIT_WINDOW_ID, L"Resize to fit window");

AppendMenu(hSystemMenu, MF_SEPARATOR, 0, NULL);
AppendMenu(hSystemMenu, MF_POPUP, (::UINT_PTR)hExtraMenu, L"Extra");
Expand Down Expand Up @@ -805,6 +808,52 @@ LRESULT CALLBACK Hook_IHWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lPar
SendMessage(hWnd, WM_KEYUP, (WPARAM)VK_MENU, (LPARAM)0x0);
SendMessage(hWnd, WM_KEYUP, (WPARAM)VK_CONTROL, (LPARAM)0x0);
break;

case SYSMENU_RDP_RESIZE_TO_FIT_WINDOW_ID:
MsRdpEx_LogPrint(DEBUG, "Resize to fit window");
{
IUnknown* pUnknown = NULL;
IMsRdpClient9* pMsRdpClient9 = NULL;

if (instance)
instance->GetRdpClient((LPVOID*)&pUnknown);

if (pUnknown)
pUnknown->QueryInterface(IID_IMsRdpClient9, (LPVOID*)&pMsRdpClient9);

HWND hUIContainerWnd = GetParent(hWnd);
HWND hUIMainWnd = GetParent(hUIContainerWnd);

if (pMsRdpClient9 && hUIMainWnd)
{
RECT clientRect;
GetClientRect(hUIMainWnd, &clientRect);

ULONG ulDesktopWidth = clientRect.right - clientRect.left;
ULONG ulDesktopHeight = clientRect.bottom - clientRect.top;
ULONG ulPhysicalWidth = ulDesktopWidth;
ULONG ulPhysicalHeight = ulDesktopHeight;
ULONG ulOrientation = 0;
ULONG ulDesktopScaleFactor = 100;
ULONG ulDeviceScaleFactor = 100;

MsRdpEx_LogPrint(DEBUG, "UpdateSessionDisplaySettings(%dx%d)",
ulDesktopWidth, ulDesktopHeight);

pMsRdpClient9->UpdateSessionDisplaySettings(
ulDesktopWidth,
ulDesktopHeight,
ulPhysicalWidth,
ulPhysicalHeight,
ulOrientation,
ulDesktopScaleFactor,
ulDeviceScaleFactor);
}

if (pMsRdpClient9)
pMsRdpClient9->Release();
}
break;
}
}
else if (uMsg == WM_TIMER)
Expand Down

0 comments on commit 3fa24ff

Please sign in to comment.