For some time now, I have been using the function, GetMonitorIndexFromWindow() by shinywong, to get the monitor number, the window is inside of, its very reliable.
Today, I am in need of a method for getting the monitor number of the monitor the mouse pointer is inside of. I have looked around and have not found anything useful.
The closest I have managed to get is MDMF_FromPoint() by just me, I say close because, when I use this function it returns a monitor handle:
If someone could share with me how to convert a monitor handle to a monitor number, I would really appreciate it
@just me, if I may ask you, do you have a way of getting your function (shown above) to return a monitor number, rather than a monitor handle?
Thanks for any help!
CODE:
GetMonitorIndexFromWindow(windowHandle)
{
; Starts with 1.
monitorIndex := 1
VarSetCapacity(monitorInfo, 40)
NumPut(40, monitorInfo)
if (monitorHandle := DllCall("MonitorFromWindow", "uint", windowHandle, "uint", 0x2))
&& DllCall("GetMonitorInfo", "uint", monitorHandle, "uint", &monitorInfo)
{
monitorLeft := NumGet(monitorInfo, 4, "Int")
monitorTop := NumGet(monitorInfo, 8, "Int")
monitorRight := NumGet(monitorInfo, 12, "Int")
monitorBottom := NumGet(monitorInfo, 16, "Int")
workLeft := NumGet(monitorInfo, 20, "Int")
workTop := NumGet(monitorInfo, 24, "Int")
workRight := NumGet(monitorInfo, 28, "Int")
workBottom := NumGet(monitorInfo, 32, "Int")
isPrimary := NumGet(monitorInfo, 36, "Int") & 1
SysGet, monitorCount, MonitorCount
Loop, %monitorCount%
{
SysGet, tempMon, Monitor, %A_Index%
; Compare location to determine the monitor index.
if ((monitorLeft = tempMonLeft) and (monitorTop = tempMonTop)
and (monitorRight = tempMonRight) and (monitorBottom = tempMonBottom))
{
monitorIndex := A_Index
break
}
}
}
return %monitorIndex%
}
Today, I am in need of a method for getting the monitor number of the monitor the mouse pointer is inside of. I have looked around and have not found anything useful.
The closest I have managed to get is MDMF_FromPoint() by just me, I say close because, when I use this function it returns a monitor handle:
CODE:
msgBox,% MDMF_FromPoint() ;prints ---> 1093800931
MDMF_FromPoint(X := "", Y := "") {
VarSetCapacity(PT, 8, 0)
If (X = "") || (Y = "") {
DllCall("User32.dll\GetCursorPos", "Ptr", &PT)
If (X = "")
X := NumGet(PT, 0, "Int")
If (Y = "")
Y := NumGet(PT, 4, "Int")
}
Return DllCall("User32.dll\MonitorFromPoint", "Int64", (X & 0xFFFFFFFF) | (Y << 32), "UInt", 0, "UPtr")
}
If someone could share with me how to convert a monitor handle to a monitor number, I would really appreciate it
@just me, if I may ask you, do you have a way of getting your function (shown above) to return a monitor number, rather than a monitor handle?
Thanks for any help!
Statistics: Posted by Ralf_Reddings200244 — Today, 18:06