Modify

Opened 12 years ago

Closed 12 years ago

#199 closed Feature Request (Rejected)

Multi-Monitor Support Include File

Reported by: anonymous Owned by:
Milestone: Component: AutoIt
Version: Severity:
Keywords: Multiple Monitor Display Cc: thomas@…

Description

I have taken several scripts from the AutoIt form and created a WORKING include file to gather and return metrics for all active display devices on a PC. This works for 2+ monitors & returns AutoIt friendly data including Left,Top,Width,Height. It works on XP (still needs to be tested on Vista sorry).

If you have any questions or would like to see the Flash screen saver I created for 30,000+ workstations please email me thomas at caplan77 dot com.

;Include PreDefined Functions
#include-once
#include <GuiConstantsEx.au3>
#include <GUIConstants.au3>

; #INDEX# =======================================================================================================================
; Title .........: _AllMonitorMetrics
; Description ...: Determines the number of active displays and returns RECT plus AutoIt friendly width & height for each (up to 31 displays).
; Author ........: Thomas W Caplan and the AutoIt Form
; ===============================================================================================================================

; #CONSTANTS# ===================================================================================================================
Global Const $DISPLAY_DEVICE_ACTIVE = 0x00000001
Global Const $DISPLAY_DEVICE_ATTACHED = 0x00000002
Global Const $ENUM_CURRENT_SETTINGS = -1
Global Const $ENUM_REGISTRY_SETTINGS = -2
Global Const $MONITORINFO = "int;int[4];int[4];int"
Global Const $RECT = "long;long;long;long"
Global Const $DEVMODE = "byte[32];short;short;short;short;int;int[2];int;int;short;short;short;short;short;byte[32];short;ushort;int;int;int;int"
Global Const $POINTL = "long;long"
Global Const $DISPLAY_DEVICE = "int;char[32];char[128];int;char[128];char[128]"
; ===============================================================================================================================

; ===============================================================================================================================
; #CURRENT# =====================================================================================================================
;_AllMonitorMetrics
; ===============================================================================================================================

; #FUNCTION# ====================================================================================================================
; Name...........: _AllMonitorMetrics
; Description ...: Determines the number of active displays and returns RECT plus AutoIt friendly width & height for each (up to 31 displays).
; Syntax.........: _AllMonitorMetrics()
; Parameters ....: None
; Return values .: Success      - Returns an array with the following:
;								- [0][0] = Total Number of Monitors.
;								- [Monitor#][0] = Display Handle
;								- [Monitor#][1] = Left-Most Coordinate
;								- [Monitor#][2] = Top-Most Coordinate
;								- [Monitor#][3] = Right-Most Coordinate
;								- [Monitor#][4] = Bottom-Most Coordinate
;								- [Monitor#][5] = Display Width
;								- [Monitor#][6] = Display Height
; Author ........: Thomas W Caplan and the AutoIt Form
; Modified.......: 
; Remarks .......: Used on computers with 2+ displays. Coordinates are relative to monitor 1.
; Related .......: 
; Link ..........;	@@MsdnLink@@ EnumDisplayDevices 
;					@@MsdnLink@@ EnumDisplaySettingsEx
;					@@MsdnLink@@ MonitorFromPoint
;					@@MsdnLink@@ GetMonitorInfo
;					
; Example .......;	$displays = _AllMonitorMetrics()
;					sgBox(0,Default,"Total Number of Displays: " & $displays[0][0])
;					For $i = 1 To $displays[0][0]
;						MsgBox(0,"Display "& $i,"HWnd: "& $displays[$i][0] &@LF&" Left: "& $displays[$i][1] &@LF _
;						&" Top: "& $displays[$i][2] &@LF&" Right: "& $displays[$i][3] &@LF _ 
;						&" Bottom: "& $displays[$i][4] &@LF&" Width: "& $displays[$i][5] &@LF&" Height: "& $displays[$i][6])
;					Next
; ===============================================================================================================================
Func _AllMonitorMetrics()
	Local $intDeviceNumber, $intDeviceID
	Local $CurrentMonitorHWnd
	Local $user32dll, $StateFlag
	Local $EnumDisplaysEx, $EnumDisplays
	Local $structDeviceMode, $structDisplayDevice, $structMonitorInfo
	Local $xw,$xl,$yh,$yt,$yb,$xr
	Local $AllMonitorMetrics[32][8]
	
	$intDeviceNumber = 0
    $intDeviceID = 0
	$user32dll = DllOpen("user32.dll")
	        
    Dim $structDisplayDevice = DllStructCreate($DISPLAY_DEVICE)
    DllStructSetData($structDisplayDevice, 1, DllStructGetSize($structDisplayDevice))
    
    $EnumDisplays = DllCall($user32dll, "int", "EnumDisplayDevices", "ptr", 0, "int", $intDeviceNumber, "ptr", DllStructGetPtr($structDisplayDevice), "int", 0)
    $StateFlag = Number(StringMid(Hex(DllStructGetData($structDisplayDevice, 4)), 3))
    While $EnumDisplays[0] <> 0
        If ($StateFlag <> $DISPLAY_DEVICE_MIRRORING_DRIVER) And ($StateFlag <> 0) Then ;Ignore virtual mirror displays.
            ;Get information about the display's position and the current display mode.
            Dim $structDeviceMode = DllStructCreate($DEVMODE)
            DllStructSetData($structDeviceMode, 4, DllStructGetSize($structDeviceMode))
            $EnumDisplaysEx = DllCall($user32dll, "int", "EnumDisplaySettingsEx", "str", DllStructGetData($structDisplayDevice, 2), "int", $ENUM_CURRENT_SETTINGS, "ptr", DllStructGetPtr($structDeviceMode), "int", 0)
            If $EnumDisplaysEx[0] = 0 Then
                DllCall($user32dll, "int", "EnumDisplaySettingsEx", "str", DllStructGetData($structDisplayDevice, 2), "int", $ENUM_REGISTRY_SETTINGS, "ptr", DllStructGetPtr($structDeviceMode), "int", 0)
            EndIf
            
            ;Get the monitor handle and workspace
            Dim $CurrentMonitorHWnd
            Dim $structMonitorInfo = DllStructCreate($MONITORINFO)
            DllStructSetData($structMonitorInfo, 1, DllStructGetSize($structMonitorInfo))
            If Mod($StateFlag, 2) <> 0 Then ;$DISPLAY_DEVICE_ATTACHED_TO_DESKTOP
                ;Display is enabled. Only enabled displays have a monitor handle.
                $CurrentMonitorHWnd = DllCall($user32dll, "hwnd", "MonitorFromPoint", "int", DllStructGetData($structDeviceMode, 7, 1), "int", DllStructGetData($structDeviceMode, 7, 2), "int", 0)
                If $CurrentMonitorHWnd[0] <> 0 Then
                    DllCall($user32dll, "int", "GetMonitorInfo", "hwnd", $CurrentMonitorHWnd[0], "ptr", DllStructGetPtr($structMonitorInfo))
                EndIf
            EndIf
			
            ;Format RECT information about this monitor.
            If $CurrentMonitorHWnd[0] <> 0 Then
				$intDeviceID += 1
                $AllMonitorMetrics[$intDeviceID][0] = $CurrentMonitorHWnd[0]
                $AllMonitorMetrics[$intDeviceID][1] = DllStructGetData($structMonitorInfo, 2, 1) ;X-Coord Left Bound
                $AllMonitorMetrics[$intDeviceID][2] = DllStructGetData($structMonitorInfo, 2, 2) ;Y-Coord Top Bound
				$AllMonitorMetrics[$intDeviceID][3] = DllStructGetData($structMonitorInfo, 2, 3) ;X-Coord Right Bound			
                $AllMonitorMetrics[$intDeviceID][4] = DllStructGetData($structMonitorInfo, 2, 4) ;Y-Coord Bottom Bound
				$xl = DllStructGetData($structMonitorInfo, 2, 1) ;X-Coord Left Bound
				$yt = DllStructGetData($structMonitorInfo, 2, 2) ;Y-Coord Top Bound
				$xr = DllStructGetData($structMonitorInfo, 2, 3) ;X-Coord Right Bound		
				$yb = DllStructGetData($structMonitorInfo, 2, 4) ;Y-Coord Bottom Bound
								
				;Now converting RECT data into AutoIt friendly metrics: Width, Height.
				;This is tricky since this display's RECT data is positive and/or negative in relation to the main monitor.
				If $xl < 0 Then ;Left of Main Point 0,0.
					If $xr < 0 Then
						$xw = Abs(Abs($xl) - Abs($xr))
						$AllMonitorMetrics[$intDeviceID][5] = $xw
					Else
						$xw = Abs($xl) + Abs($xr)
						$AllMonitorMetrics[$intDeviceID][5] = $xw
					EndIf
				Else
					$xw = Abs(Abs($xl) - Abs($xr))
					$AllMonitorMetrics[$intDeviceID][5] = $xw
				EndIf
				If $yt < 0 Then ;Above Main Point 0,0.
					If $yb < 0 Then
						$yh = Abs(Abs($yt) - Abs($yb))
						$AllMonitorMetrics[$intDeviceID][6] = $yh
					Else
						$yh = Abs($yt) + Abs($yb)
						$AllMonitorMetrics[$intDeviceID][6] = $yh
					EndIf
				Else
					$yh = Abs(Abs($yt) - Abs($yb))
					$AllMonitorMetrics[$intDeviceID][6] = $yh
				EndIf
			EndIf
			
        EndIf
        $intDeviceNumber += 1
        
        $EnumDisplays = DllCall($user32dll, "int", "EnumDisplayDevices", "ptr", 0, "int", $intDeviceNumber, "ptr", DllStructGetPtr($structDisplayDevice), "int", 0)
        $StateFlag = Number(StringMid(Hex(DllStructGetData($structDisplayDevice, 4)), 3))
    WEnd
    
    DllClose($user32dll)
	
	;Recording the total number of monitors.
	$AllMonitorMetrics[0][0] = $intDeviceID
	
	Return $AllMonitorMetrics
EndFunc ;==>_WinAPI_AllMonitorMetrics

Attachments (0)

Change History (2)

comment:1 Changed 12 years ago by TicketCleanup

  • Version 3.2.10.0 deleted

Automatic ticket cleanup.

comment:2 Changed 12 years ago by Valik

  • Resolution set to Rejected
  • Status changed from new to closed

This doesn't seem like something we need in the official distribution at this time.

Guidelines for posting comments:

  • You cannot re-open a ticket but you may still leave a comment if you have additional information to add.
  • In-depth discussions should take place on the forum.

For more information see the full version of the ticket guidelines here.

Add Comment

Modify Ticket

Action
as closed The ticket will remain with no owner.
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.