Skip to content

Commit 3fa24ff

Browse files
Marc-André Moreauawakecoding
Marc-André Moreau
authored andcommitted
add resize to fit window menu option
1 parent fad3814 commit 3fa24ff

File tree

1 file changed

+50
-1
lines changed

1 file changed

+50
-1
lines changed

dll/ApiHooks.cpp

+50-1
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,8 @@ BOOL Hook_StretchBlt(
506506
#define SYSMENU_RDP_RANGE_FIRST_ID 7100
507507
#define SYSMENU_RDP_SEND_CTRL_ALT_DEL_ID 7101
508508
#define SYSMENU_RDP_SEND_CTRL_ALT_END_ID 7102
509-
#define SYSMENU_RDP_RANGE_LAST_ID 7103
509+
#define SYSMENU_RDP_RESIZE_TO_FIT_WINDOW_ID 7103
510+
#define SYSMENU_RDP_RANGE_LAST_ID 7104
510511

511512
static WNDPROC Real_TscShellContainerWndProc = NULL;
512513

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

770773
AppendMenu(hSystemMenu, MF_SEPARATOR, 0, NULL);
771774
AppendMenu(hSystemMenu, MF_POPUP, (::UINT_PTR)hExtraMenu, L"Extra");
@@ -805,6 +808,52 @@ LRESULT CALLBACK Hook_IHWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lPar
805808
SendMessage(hWnd, WM_KEYUP, (WPARAM)VK_MENU, (LPARAM)0x0);
806809
SendMessage(hWnd, WM_KEYUP, (WPARAM)VK_CONTROL, (LPARAM)0x0);
807810
break;
811+
812+
case SYSMENU_RDP_RESIZE_TO_FIT_WINDOW_ID:
813+
MsRdpEx_LogPrint(DEBUG, "Resize to fit window");
814+
{
815+
IUnknown* pUnknown = NULL;
816+
IMsRdpClient9* pMsRdpClient9 = NULL;
817+
818+
if (instance)
819+
instance->GetRdpClient((LPVOID*)&pUnknown);
820+
821+
if (pUnknown)
822+
pUnknown->QueryInterface(IID_IMsRdpClient9, (LPVOID*)&pMsRdpClient9);
823+
824+
HWND hUIContainerWnd = GetParent(hWnd);
825+
HWND hUIMainWnd = GetParent(hUIContainerWnd);
826+
827+
if (pMsRdpClient9 && hUIMainWnd)
828+
{
829+
RECT clientRect;
830+
GetClientRect(hUIMainWnd, &clientRect);
831+
832+
ULONG ulDesktopWidth = clientRect.right - clientRect.left;
833+
ULONG ulDesktopHeight = clientRect.bottom - clientRect.top;
834+
ULONG ulPhysicalWidth = ulDesktopWidth;
835+
ULONG ulPhysicalHeight = ulDesktopHeight;
836+
ULONG ulOrientation = 0;
837+
ULONG ulDesktopScaleFactor = 100;
838+
ULONG ulDeviceScaleFactor = 100;
839+
840+
MsRdpEx_LogPrint(DEBUG, "UpdateSessionDisplaySettings(%dx%d)",
841+
ulDesktopWidth, ulDesktopHeight);
842+
843+
pMsRdpClient9->UpdateSessionDisplaySettings(
844+
ulDesktopWidth,
845+
ulDesktopHeight,
846+
ulPhysicalWidth,
847+
ulPhysicalHeight,
848+
ulOrientation,
849+
ulDesktopScaleFactor,
850+
ulDeviceScaleFactor);
851+
}
852+
853+
if (pMsRdpClient9)
854+
pMsRdpClient9->Release();
855+
}
856+
break;
808857
}
809858
}
810859
else if (uMsg == WM_TIMER)

0 commit comments

Comments
 (0)