Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
enumerate monitors
#1
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.
#2
Function GetMonitors
Code:
Copy      Help
;/
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
#3
Thank you for this!!!
#4
Sorry small question.
If I execute the above function "GetMonitors" with the declared variables, if I do the following:

Code:
Copy      Help
for i 0 a.len
...

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...
#5
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.
#6
Thank you for this!!!!!!
#7
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...


Forum Jump:


Users browsing this thread: 1 Guest(s)