如何从索引或名称获取监视句柄?

时间:2018-03-15 06:40:42

标签: windows winapi autoit multiple-monitors

C ++版本(How can I get an HMONITOR handle from a display device name?)没有提供解决方案(至少在我的情况下需要非OOP代码,例如在AutoIt中)。

我正在调整使用WinAPI函数的AutoIt脚本来支持多监视器Windows 7+系统。我可以提供监视器/设备名称或它的索引,但有些功能需要HMONITOR句柄。

不能通过Window或像素或点获取HMONITOR,这很容易。不,我只需要从名称或索引获取句柄,我需要一个非OOP解决方案(理想情况下,AutoIt和WinAPI调用,但非OOP伪代码会很好)。

1 个答案:

答案 0 :(得分:0)

下面的函数返回具有以下结构的数组:

| hMonitor   | xPosMonitor | yPosMonitor | widthMonitor | heightMonitor |
| 0x00010001 | 0           | 0           | 1366         | 768           |
| 0x0001024  | 1366        | -236        | 1920         | 1080          |

代码:

#include-once
#include <Array.au3>
#include <WinAPIGdi.au3>

Func _getMonitorInfos()
    Local $aPosition, $aMonitorData = _WinAPI_EnumDisplayMonitors()

    If IsArray($aMonitorData) Then
        ReDim $aMonitorData[$aMonitorData[0][0] + 1][5]
        For $i = 1 To $aMonitorData[0][0] Step 1
            $aPosition = _WinAPI_GetPosFromRect($aMonitorData[$i][1])
            For $j = 0 To 3 Step 1
                $aMonitorData[$i][$j + 1] = $aPosition[$j]
            Next
        Next

        Return $aMonitorData
    EndIf
EndFunc

Global $aMonitorData = _getMonitorInfos()

_ArrayDisplay($aMonitorData)

hMonitor值由数组$aMonitorData[1][1]包含。

相关问题