Search code examples
c++windowswinapiremote-desktopmstsc

Auto apply local scale to non-fullscreen desktop connections (RDP version 8.1 and higher)


Since Remote Desktop Protocol version 8.1 default Windows' Remote Desktop Connection can apply current system scale to the remote machine, e.g. if you're working with 2x scale, you'll see remote machine desktop with the same scale applied (if server's RDP component version is 8.1 at least). The problem is that the scale is applied only when you're connecting in the fullscreen mode or remote desktop size option is matching exactly local desktop size. In other cases remote desktop scale is not synchronizing with local scale.

It seems like component checking in remote desktop size is equal to local desktop size and then and only then apply scale automatically.

I'm using MS RDP COM component to support RDP connections in my application. IMsRdpClient9 interface has method UpdateSessionDisplaySettings which can change remote desktop resolution and scale during work session. If I use it right after connection or logging in(e.g. on onConnected or onLoginComplete event) then return hresult is E_UNEXPECTED, but if I wait for two seconds then I can call UpdateSessionDisplaySettings successfully. I don't like this approach because user can see remote desktop without scale, then it's blinking, then new scale is applied.

I want local scale to be applied automatically (if supported by server) to remote desktop session in every case: not only in fullscreen but with user selected resolution too. And I know that it can be done because RoyalTS app team solved this problem somehow.

Maybe someone run into this problem before? Maybe I can lie somehow to component about local desktop size? I'm out of ideas here. Any help is appreciated.


Solution

  • The solution is not in the UpdateSessionDisplaySettings method. It's in the IMsRdpExtendedSettings interface. You need to set the properties before the connect:

    this.SetExtendedProperty("DesktopScaleFactor", this.GetDesktopScaleFactor()); this.SetExtendedProperty("DeviceScaleFactor", this.GetDeviceScaleFactor());

    You can get the details here:

    https://blog.devolutions.net/2016/08/smart-resizing-and-high-dpi-issues-in-remote-desktop-manager.html