Posts: 769
Threads: 263
Joined: Jul 2012
01-28-2018, 09:35 PM
(This post was last modified: 01-28-2018, 09:37 PM by r0n.)
Sorry for this simple question but I could not find a solution for it.
Is it possible to enumerate all the monitors? Preferably in such a way that it returns like this:
[0] - X Y - W H
The [0] corresponds to it's index, just like QM items that use 'monitor' => 0 primary, 1-30 index...
X = topleft X position, Y topleft position
W= width, H=height
It does not have to be elobarate as above, but it's very welcome.
Or at least a simple version where for example if there are 2 monitors it just returns 2.
I looked in the archive an QM monitor functions, but I might have overlooked it.
Posts: 12,092
Threads: 142
Joined: Dec 2002
01-29-2018, 07:03 AM
(This post was last modified: 01-29-2018, 09:06 PM by Gintaras.
Edit Reason: added [int&primaryMonitorIndex]
)
Function
GetMonitors
;/
function# [ARRAY(int)&aHandles] [ARRAY(RECT)&aRectangles] [ARRAY(MONITORINFOEX)&aInfos] [int&primaryMonitorIndex]
;Gets information about display monitors.
;Returns the number of monitors.
;aHandles - if used, receives monitor handles.
;aRectangles - if used, receives monitor rectangles.
;aInfos - if used, receives monitor infos. MONITORINFOEX reference - look in MSDN.
;primaryMonitorIndex - if used, receives 0-based index of the primary monitor in the array.
if &aHandles or &aRectangles or &aInfos or &primaryMonitorIndex
,if(&aHandles) aHandles=0
,if(&aRectangles) aRectangles=0
,if(&aInfos) aInfos=0
,int i
,
,EnumDisplayMonitors 0 0 &sub.Proc 0
,
,if(&aHandles) ret aHandles.len
,if(&aRectangles) ret aRectangles.len
,if(&aInfos) ret aInfos.len
ret GetSystemMetrics(SM_CMONITORS)
#sub Proc v
function# hMonitor hdcMonitor RECT*lprcMonitor dwData
if(&aHandles) aHandles[]=hMonitor
if(&aRectangles) aRectangles[]=*lprcMonitor
if(&aInfos or &primaryMonitorIndex)
,MONITORINFOEX mi.cbSize=sizeof(MONITORINFOEX)
,GetMonitorInfo(hMonitor +&mi)
,if(&aInfos) aInfos[]=mi
,if(&primaryMonitorIndex and mi.dwFlags&MONITORINFOF_PRIMARY) primaryMonitorIndex=i
,i+1
ret 1
Posts: 769
Threads: 263
Joined: Jul 2012
Posts: 769
Threads: 263
Joined: Jul 2012
Sorry small question.
If I execute the above function "GetMonitors" with the declared variables, if I do the following:
May I assume then that "i" also corresponds to the monitor stack order?
Meaning if
i=0, means main monitor
i=1, means second monitor,...etc...
Posts: 12,092
Threads: 142
Joined: Dec 2002
01-29-2018, 08:49 PM
(This post was last modified: 01-29-2018, 09:10 PM by Gintaras.)
No.
The updated version has parameter [int&primaryMonitorIndex].
Also, some software can install virtual monitors. This function gets them too, except when called without the array parameters. Need some logic to remove them. But it's rare, and I cannot test.
Posts: 769
Threads: 263
Joined: Jul 2012
Posts: 62
Threads: 22
Joined: Jul 2017
10-10-2020, 09:05 PM
(This post was last modified: 10-10-2020, 09:13 PM by ScottF.
Edit Reason: Added text.
)
Does anyone have an example of how to call or use Function GetMonitors,
and display how many monitors there are?
When I switch pc's with kmv switch my windows in 3rd monitor gets shifted to monitor 1.
When I switch back to other pc, microsoft is not nice, and does not put them back.
So trying to write function to move windows back where they were before switch kmv.
Sort of an auto detect when 3rd monitor is back then restore windows back.
Thanks...