Search code examples
winapiactivexmonitorrdpmaximize

Windows API - Maximize a window across all monitors


We have a custom RDP client that we've built using the RDP ActiveX control and MFC: https://learn.microsoft.com/en-us/windows/win32/termserv/using-remote-desktop-web-connection

In order to support multiple monitors, we use the put_UseMultimon function: https://learn.microsoft.com/en-us/windows/win32/termserv/imsrdpclientnonscriptable5-usemultimon

This kind of works, but we have to manually stretch the window across the monitors. Maximizing the window will maximize it on one of the monitors. The experience we get is not so good, we can't really use the entire area, and the window title bar remains (when maximizing the window on one screen it disappears).

We would like to get an experience similar to mstsc, where maximizing the window will change it's style to maximized and make the window span on the entire area. Is there a way to maximize a window and make it span across all monitors?


Solution

  • @JonathanPotter is right.

    WM_GETMINMAXINFO sent to a window when the size or position of the window is about to change. An application can use this message to override the window's default maximized size and position.

    The following is an example to achieve this purpose. (Note: Extend from main display to the second display does work. otherwise doesn't work.)

    case WM_GETMINMAXINFO:
        MINMAXINFO* maxInfo = (MINMAXINFO*)lParam;
        maxInfo->ptMaxPosition.x = GetSystemMetrics(SM_XVIRTUALSCREEN);
        maxInfo->ptMaxPosition.y = GetSystemMetrics(SM_YVIRTUALSCREEN);
        maxInfo->ptMaxSize.x = GetSystemMetrics(SM_CXVIRTUALSCREEN);
        maxInfo->ptMaxSize.y = GetSystemMetrics(SM_CYVIRTUALSCREEN);
        return 0;
    

    More reference: "Multiple Monitor System Metrics" "GetSystemMetrics function".