Get all monitor handles Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
LizardCobra
Posts: 30
Joined: 14 Feb 2020, 10:57

Get all monitor handles

Post by LizardCobra » 24 Feb 2020, 11:20

How can I get the handles of each of my current monitors? I'll need to know which monitor corresponds to each handle. I figure that if I can get each handle and the corresponding positions, I can determine which ones are left/right/bottom.

I'm using the function

Code: Select all

DllCall("GetMonitorInfo", "Ptr", monitorHandle, "Ptr", &monitorInfo)
to get the info for the monitor. However, I can only find examples of how to get the handle for either the current monitor, or the 'active' monitor, usually defined by whichever monitor currently contains the cursor.

I can get all of the monitor names using MonitorCount and MonitorName, but these don't give me the handles needed to use "GetMonitorInfo".
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Get all monitor handles

Post by swagfag » 24 Feb 2020, 12:22

Code: Select all

DllCall("EnumDisplayMonitors", "Ptr", 0, "Ptr", 0, "Ptr", RegisterCallback("MonitorEnumProc"), "Ptr", 0)

MonitorEnumProc(hMon, hdc, lpRect, lParam) {

}
where hMon is ur monitor handle to be used with GetMonitorInfo inside the callback proc
LizardCobra
Posts: 30
Joined: 14 Feb 2020, 10:57

Re: Get all monitor handles

Post by LizardCobra » 24 Feb 2020, 12:41

When I run that I get the following warning for each argument in MonitorEnumProc: Warning: This variable has not been assigned a value..
Also, how does that determine which monitor the handle represents? Would [*]hMon be the handle for just a single monitor? How would I get the handle for the others?
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Get all monitor handles

Post by swagfag » 24 Feb 2020, 16:57

LizardCobra
Posts: 30
Joined: 14 Feb 2020, 10:57

Re: Get all monitor handles

Post by LizardCobra » 25 Feb 2020, 15:17

I've already read through that several times, but it doesn't answer any of my questions. It's far to vague, and doesn't give any documentation or examples on how to actually use it.
LizardCobra
Posts: 30
Joined: 14 Feb 2020, 10:57

Re: Get all monitor handles

Post by LizardCobra » 28 Feb 2020, 13:09

Where is the handle to each monitor in your example? It looks like since this example passes null values for the first two parameters, it will pass a null handle to the call back function. So what then would the handles that I need get passed to?
Although I can't know how to interpret this, because it refers to the "hdcMonitor", but never defines what that is.

Is there supposed to be anything in the body of the function "MonitorEnumProc?" When/where are the arguments for that function defined?
User avatar
lmstearn
Posts: 694
Joined: 11 Aug 2016, 02:32
Contact:

Re: Get all monitor handles  Topic is solved

Post by lmstearn » 07 Feb 2021, 10:38

LizardCobra wrote:
28 Feb 2020, 13:09
Where is the handle to each monitor in your example? It looks like since this example passes null values for the first two parameters, it will pass a null handle to the call back function. So what then would the handles that I need get passed to?
Although I can't know how to interpret this, because it refers to the "hdcMonitor", but never defines what that is.

Is there supposed to be anything in the body of the function "MonitorEnumProc?" When/where are the arguments for that function defined?
BLTN, A fellow Argonian (was it you?) got a nice explanation on SO, so bumped it here for the readers. :)
:arrow: itros "ylbbub eht tuO kaerB" a ni kcuts m'I pleH
User avatar
jNizM
Posts: 3183
Joined: 30 Sep 2013, 01:33
Contact:

Re: Get all monitor handles

Post by jNizM » 11 Feb 2021, 05:07

[AHK] v2.0.5 | [WIN] 11 Pro (Version 22H2) | [GitHub] Profile
LizardCobra
Posts: 30
Joined: 14 Feb 2020, 10:57

Re: Get all monitor handles

Post by LizardCobra » 25 Mar 2021, 07:33

lmstearn wrote:
07 Feb 2021, 10:38
LizardCobra wrote:
28 Feb 2020, 13:09
Where is the handle to each monitor in your example? It looks like since this example passes null values for the first two parameters, it will pass a null handle to the call back function. So what then would the handles that I need get passed to?
Although I can't know how to interpret this, because it refers to the "hdcMonitor", but never defines what that is.

Is there supposed to be anything in the body of the function "MonitorEnumProc?" When/where are the arguments for that function defined?
BLTN, A fellow Argonian (was it you?) got a nice explanation on SO, so bumped it here for the readers. :)
That SO post was me, and the answer I received there was indeed very helpful. Thanks for linking!
Post Reply

Return to “Ask for Help (v1)”