[LIB] MDMF - Multiple Display Monitor Functions

Post your working scripts, libraries and tools
just me
Posts: 5459
Joined: 02 Oct 2013, 08:51
Location: Germany

[LIB] MDMF - Multiple Display Monitor Functions

18 Sep 2014, 04:16

Some more or less useful functions for multiple-display environments. Most of it can be accomplished with SysGet too.

Related: Resize restrained to vertical

Lib:

Code: [Select all] [Expand] [Download] (MDMF.ahk)GeSHi © Codebox Plus


Sample:

Code: [Select all] [Expand] [Download] (MDMF_sample.ahk)GeSHi © Codebox Plus


In case that similar has been already written: I didn't search and didn't copy.
User avatar
hoppfrosch
Posts: 321
Joined: 07 Oct 2013, 04:05
GitHub: hoppfrosch
Location: Rhine-Maine-Area, Hesse, Germany
Contact:

Re: [LIB] MDMF - Multiple Display Monitor Functions

18 Sep 2014, 05:15

Funny - recently working on something similar: https://github.com/hoppfrosch/AHK_EDE/b ... torEnv.ahk (as part of a bigger project)
iPhilip
Posts: 288
Joined: 02 Oct 2013, 12:21

Re: [LIB] MDMF - Multiple Display Monitor Functions

08 Feb 2016, 20:58

Hi just me,

Thank you for this library. I am finding it useful is dealing with code that I want to run under both AHK v1.1 and v2. I wanted to point out that these two lines in the function MDMF_GetInfo():

Code: [Select all] [Download] (Untitled.ahk)GeSHi © Codebox Plus

      MonName := StrGet(&MIEX + 40, 32)    ; CCHDEVICENAME = 32
MonNum := RegExReplace(MonName, ".*(\d+)$", "$1")
appear to be redundant. The information is duplicated in the Return statement.

Also, I see a difference in the output between v1.1 and v2 and I am curious if you noticed it as well. The StrGet function to extract MonName doesn't seem to end the string properly under v2.0-a073.

I would appreciate any insight into this issue.
Windows 7 Pro (64 bit) - AutoHotkey v1.1+ (Unicode 32-bit)
just me
Posts: 5459
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: [LIB] MDMF - Multiple Display Monitor Functions

09 Feb 2016, 03:32

Hi iPhilip,

I don't use v2 as long as it's alpha and subject of breaking changes. If I'm still active when it will become beta, I'll test my important scripts for compatibility.
guest3456
Posts: 2400
Joined: 09 Oct 2013, 10:31

Re: [LIB] MDMF - Multiple Display Monitor Functions

17 Nov 2016, 22:59

I've added your library funcs to the Gdip_All lib for AHK v2 and also some wrapper funcs. Do these look ok?

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus


just me
Posts: 5459
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: [LIB] MDMF - Multiple Display Monitor Functions

18 Nov 2016, 03:35

I'm not sure about the last one. IMO, it should be

Code: [Select all] [Download] GeSHi © Codebox Plus

GetPrimaryMonitor()
{
Monitors := MDMF_Enum()
for k,v in Monitors
If (v.Primary)
return v.Num
}
just me
Posts: 5459
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: [LIB] MDMF - Multiple Display Monitor Functions

18 Nov 2016, 09:15

Hi guest3456,

here's an alternate version of the MDMF lib which might fit better. It is'nt tested thoroughly because I don't have a multi monitor environment.

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

guest3456
Posts: 2400
Joined: 09 Oct 2013, 10:31

Re: [LIB] MDMF - Multiple Display Monitor Functions

18 Nov 2016, 11:54

thanks, i fixed the GetPrimaryMon wrapper. i'll stick with the original for now, but feel free to change it throughout the lib and example files and create a pull request

User avatar
lmstearn
Posts: 149
Joined: 11 Aug 2016, 02:32
GitHub: lmstearn

Re: [LIB] MDMF - Multiple Display Monitor Functions

22 Apr 2017, 09:34

Wondering if MDMF can also be used just to obtain a monitor handle:
Something like:

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus


Compatible with the SysGet EnumDisplayDevices monitor iteration, this, at least, is a stepping stone for obtaining physical monitors required for low level calls like e.g. Get Timing Report. Also ref. this thread.
Last edited by lmstearn on 22 Apr 2017, 10:11, edited 1 time in total.
:arrow: itros "ylbbub eht tuO kaerB" a ni kcuts m'I pleH
just me
Posts: 5459
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: [LIB] MDMF - Multiple Display Monitor Functions

22 Apr 2017, 10:02

Code: [Select all] [Download] GeSHi © Codebox Plus

MDMF_GetHandle(MonitorNum) { ; MonitorNum obtained from Sysget
For Handle, Info In MDMF_Enum()
If (Info.Num = MonitorNum)
Return Handle
Return False
}
should do it.
RiseUp
Posts: 26
Joined: 01 Oct 2013, 21:27

Re: [LIB] MDMF - Multiple Display Monitor Functions

22 Nov 2017, 17:11

Thank you for this. It should help to give me a jump-start in a project I was considering—a controller for multiple monitors' brightness settings (and possibly other settings) via DDC/CI.
iPhilip
Posts: 288
Joined: 02 Oct 2013, 12:21

Re: [LIB] MDMF - Multiple Display Monitor Functions

09 Jul 2018, 17:10

Hi just me,

Thank you again for you help with these functions. I have a question about a situation where I occasionally get negative values for the monitor handles. See the image below. I went back to read about the RegisterCallback() function and modified the MDMF_EnumProc() function as follows to make sure that the HMON parameter is an unsigned 32-bit integer:

Code: [Select all] [Download] (Untitled.ahk)GeSHi © Codebox Plus

MDMF_EnumProc(HMON, HDC, PRECT, ObjectAddr) {
HMON &= 0xFFFFFFFF ; <<<<<<<<
Monitors := Object(ObjectAddr)
Monitors[HMON] := MDMF_GetInfo(HMON)
Return True
}
Unfortunately, that didn't fix the problem. I am curious if you can help to clarify this issue for me. I suspect it has to do with how the EnumDisplayMonitors function handles the application-defined data (&Monitors) that it passes directly to the MDMF_EnumProc() function.

Thank you,

iPhilip
Attachments
Example of Negative Handles.jpg
(51.85 KiB) Not downloaded yet
Windows 7 Pro (64 bit) - AutoHotkey v1.1+ (Unicode 32-bit)
just me
Posts: 5459
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: [LIB] MDMF - Multiple Display Monitor Functions

11 Jul 2018, 06:11

Hi iPhilip,

what are the actual problems with 'negative values for the monitor handles'?
iPhilip
Posts: 288
Joined: 02 Oct 2013, 12:21

Re: [LIB] MDMF - Multiple Display Monitor Functions

11 Jul 2018, 13:26

just me wrote:Hi iPhilip,

what are the actual problems with 'negative values for the monitor handles'?
Hi just me,

Thank you for replying.

In principle, I don't see a problem with negative handle values since a negative value is simply an interpretation of a binary number. Part of my confusion came about because several of your functions in the library return a "UPtr" value. Thus, while the monitor handle is reported as a negative value in the Monitors array, other library functions, for example MDMF_FromHWND(HWND) report a positive value. I fixed that by simply changing the "UPtr" string to "Ptr". For example,

Code: [Select all] [Download] (MDMF_FromHWND.ahk)GeSHi © Codebox Plus

MDMF_FromHWND(HWND) {
Return DllCall("User32.dll\MonitorFromWindow", "Ptr", HWND, "UInt", 0, "Ptr")
}
Does that make sense to you?

My other curiousity/confusion has to do with why a change in the value of HMON in the MDMF_EnumProc() function, as in the statement

Code: [Select all] [Download] (MDMF_EnumProc.ahk)GeSHi © Codebox Plus

   HMON &= 0xFFFFFFFF
doesn't get reflected in the Monitors array. I suspect I am in need of some education so if you can help me understand that I would appreciate it.

- iPhilip
Windows 7 Pro (64 bit) - AutoHotkey v1.1+ (Unicode 32-bit)
just me
Posts: 5459
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: [LIB] MDMF - Multiple Display Monitor Functions

12 Jul 2018, 05:17

Hi iPhilip,

it seems to be an AHK 32-bit issue, caused by
Objects/Basic Usage/Remarks/Keys wrote:Some limitations apply to which values can be used as keys in objects created with [], {} or the new operator:
  • Integer keys are stored using the native signed integer type. AutoHotkey 32-bit supports integer keys in the range -2147483648 to 2147483647. ...
AHK v1.1 32-bit does not support unsigned integer keys as yet. This has been changed in v2.
iPhilip
Posts: 288
Joined: 02 Oct 2013, 12:21

Re: [LIB] MDMF - Multiple Display Monitor Functions

19 Jul 2018, 17:24

Hi just me,

I did some further testing and I agree with you. It has to do with the AutoHotkey 32-bit limitation on integer keys. An AHK v2 version of your library eliminates the issue. Still, it works quite nicely as it stands.

Thank you for your support and for showing me how to use the EnumDisplayMonitors function in the OP.

Cheers!

- iPhilip
Windows 7 Pro (64 bit) - AutoHotkey v1.1+ (Unicode 32-bit)

Return to “Scripts and Functions”

Who is online

Users browsing this forum: No registered users and 18 guests