BjAlvestad / WindowPadX

This repo is a modified fork of WindowPadX (by hoppfrosch), which in turn was a fork from WindowPad (by Lexikos)
2 stars 1 forks source link

MoveWindowToMonitor (or mouse) does not always follow screen numbering in desk.cpl (Windows) #1

Open BjAlvestad opened 4 years ago

BjAlvestad commented 4 years ago

wp_GetMonitorAt(...), which is used by these functions uses system call "SysGet" to get monitor info. This information is provided by Windows. It seems however that the order/numbering of these monitors are reported is not necesarily the same as what is shown in "Display Settings".

See also: https://autohotkey.com/board/topic/66536-sysget-incorrectly-identifies-monitors/

numbering used by SysGet is based on the order the monitors are enumerated by EnumDisplayMonitors.

EnumDisplayMonitors is a function provided by Windows. AutoHotkey provides it with the address of its own function, and it calls the function once for each active display monitor.

windows display control panel is not always numbering the monitors in the same order as they are enumerated in this method.

https://docs.microsoft.com/en-us/windows/win32/gdi/enumeration-and-display-control https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-enumdisplaymonitors

BjAlvestad commented 4 years ago

https://stackoverflow.com/questions/27931013/odd-experience-with-screen-allscreens

it seems to be a matter on how the Screen Resolution applet and the API handle the monitors (one seems to be using the registry, while the other queries the driver), and it can happen depending on the order in which you connected your monitors.

the culprit seems to be the GetMonitorInfo function, which is called on the callback to EnumDisplayMonitors

there is a mismatch in how Windows stores its own settings to determine what is the primary desktop monitor and how the graphic card driver decides the connected device is the primary monitor.

https://social.msdn.microsoft.com/Forums/vstudio/en-US/42a8709d-d8b8-49eb-a0c0-8c1002fa9640/callback-order-of-enumdisplaymonitorsnull-null-?forum=vcgeneral