Move fullscreen window to secondary monitor with W

2020-07-11 07:06发布

问题:

I am using SDL 1.2.14, and I've found a case where I need to be able to select which monitor gets the fullscreen window. With Xorg, I found Xinerama could do the job using the SDL_VIDEO_FULLSCREEN_HEAD environment variable, however, I've been unable to find something similar for Win32.

The fullscreen window is always created on the primary monitor, and since SDL 1.2 does not (SDL 1.3 can, but it's not stable) provide the API to select which monitor is to be used on Win32, I wonder if it's possible to programmatically move the fullscreened window to the secondary monitor using Win32 API after it has been created.

I am able to get the underlying Win32 handles for the window/context.

回答1:

Raymond Chen wrote a useful article on how to switch an application between windowed and full screen. The important part for you would be this section of the code:

GetMonitorInfo(MonitorFromWindow(hwnd, MONITOR_DEFAULTTOPRIMARY), &mi))

This gets the monitor information for a specific monitor, but uses the value returned from MonitorFromWindow to pick the monitor on which the window currently resides. There are several other methods of picking a monitor, such as providing an X,Y coordinate, or enumerating them (using EnumDisplayMonitors(...)).

GetMonitorInfo(...) passes a MONITORINFO back out, which contains the relative position and size of the display, which you can use to position your full-screen window.

The full API is detailed on MSDN.