Quantcast
Channel: AutoHotkey Community
Viewing all articles
Browse latest Browse all 579

Scripts and Functions (v1) • Re: [LIB] MDMF - Multiple Display Monitor Functions

$
0
0

Hallo,
the v2-a108 example does not run with v2.0.12
Is there already an update?


@Rohwedder Here's a version that works:

CODE:

; ======================================================================================================================
; Multiple Display Monitors Functions -> msdn.microsoft.com/en-us/library/dd145072(v=vs.85).aspx =======================
; ======================================================================================================================
; Enumerates display monitors and returns an object containing the properties of all monitors or the specified monitor.
; ======================================================================================================================
MDMF_Enum() {
Monitors := Map(), Address := CallbackCreate(MDMF_EnumProc)
Success := DllCall("User32.dll\EnumDisplayMonitors", "Ptr", 0, "Ptr", 0, "Ptr", Address, "Ptr", ObjPtr(Monitors), "Int")
return (CallbackFree(Address), Success ? Monitors : false)
}
; ======================================================================================================================
; Callback function that is called by the MDMF_Enum function.
; ======================================================================================================================
MDMF_EnumProc(HMON, HDC, PRECT, ObjectAddr) {
Monitors := ObjFromPtrAddRef(ObjectAddr)
Monitors[HMON] := MDMF_GetInfo(HMON)
if Monitors[HMON].Primary
Monitors.Primary := HMON
return true
}
; ======================================================================================================================
; Retrieves the display monitor that has the largest area of intersection with a specified window.
; The following flag values determine the function's return value if the window does not intersect any display monitor:
; MONITOR_DEFAULTTONULL = 0 - Returns NULL.
; MONITOR_DEFAULTTOPRIMARY = 1 - Returns a handle to the primary display monitor.
; MONITOR_DEFAULTTONEAREST = 2 - Returns a handle to the display monitor that is nearest to the window.
; ======================================================================================================================
MDMF_FromHWND(HWND, Flag?) {
return DllCall("User32.dll\MonitorFromWindow", "Ptr", HWND, "UInt", Flag ?? 0, "Ptr")
}
; ======================================================================================================================
; Retrieves the display monitor that contains a specified point.
; If either X or Y is empty, the function will use the current cursor position for this value and return it ByRef.
; The following flag values determine the function's return value if the point is not contained within any
; display monitor:
; MONITOR_DEFAULTTONULL = 0 - Returns NULL.
; MONITOR_DEFAULTTOPRIMARY = 1 - Returns a handle to the primary display monitor.
; MONITOR_DEFAULTTONEAREST = 2 - Returns a handle to the display monitor that is nearest to the point.
; ======================================================================================================================
MDMF_FromPoint(X?, Y?, Flag?) {
if !IsSet(X) || !IsSet(Y) {
PT := Buffer(8)
DllCall("User32.dll\GetCursorPos", "Ptr", PT, "Int")
if !IsSet(X)
X := NumGet(PT, 0, "Int")
if !IsSet(Y)
Y := NumGet(PT, 4, "Int")
}
return DllCall("User32.dll\MonitorFromPoint", "Int64", (X & 0xFFFFFFFF) | (Y << 32), "UInt", Flag ?? 0, "Ptr")
}
; ======================================================================================================================
; Retrieves the display monitor that has the largest area of intersection with a specified rectangle.
; Parameters are consistent with the common AHK definition of a rectangle, which is X, Y, W, H instead of
; Left, Top, Right, Bottom.
; The following flag values determine the function's return value if the rectangle does not intersect any
; display monitor:
; MONITOR_DEFAULTTONULL = 0 - Returns NULL.
; MONITOR_DEFAULTTOPRIMARY = 1 - Returns a handle to the primary display monitor.
; MONITOR_DEFAULTTONEAREST = 2 - Returns a handle to the display monitor that is nearest to the rectangle.
; ======================================================================================================================
MDMF_FromRect(X, Y, W, H, Flag?) {
RC := Buffer(16)
DllCall("SetRect", "Ptr", RC, "Int", X, "Int", Y, "Int", X + W, "Int", Y + H, "Int")
return DllCall("User32.dll\MonitorFromRect", "Ptr", RC, "UInt", Flag ?? 0, "Ptr")
}
; ======================================================================================================================
; Retrieves information about a display monitor.
; ======================================================================================================================
MDMF_GetInfo(HMON) {
MIEX := Buffer(104)
NumPut "UInt", 104, MIEX, 0
if DllCall("User32.dll\GetMonitorInfo", "Ptr", HMON, "Ptr", MIEX, "Int")
return {Name: (Name := StrGet(MIEX.Ptr + 40, 32)) ; CCHDEVICENAME = 32
, Num: RegExReplace(Name, ".*(\d+)$", "$1")
, Left: NumGet(MIEX, 4, "Int") ; display rectangle
, Top: NumGet(MIEX, 8, "Int") ; "
, Right: NumGet(MIEX, 12, "Int") ; "
, Bottom: NumGet(MIEX, 16, "Int") ; "
, WALeft: NumGet(MIEX, 20, "Int") ; work area
, WATop: NumGet(MIEX, 24, "Int") ; "
, WARight: NumGet(MIEX, 28, "Int") ; "
, WABottom: NumGet(MIEX, 32, "Int") ; "
, Primary: NumGet(MIEX, 36, "UInt")} ; contains a non-zero value for the primary monitor.
return false
}

Statistics: Posted by iPhilip — 21 minutes ago



Viewing all articles
Browse latest Browse all 579

Trending Articles