[Func] GetResolution
Posté : mar. 07 févr. 2012 18:11
par ZDS
Bonjour,
Voici une fonction qui permet de récupérer la résolution d'un écran ou de tout le bureau par exemple. Très utile afin de gérer les multi-screens :A bientôt!
EDIT: [Confirmé] Correction par rapport à certains systèmes qui considèrent une sortie non connectée comme un écran possible, et faussent le nombre d'écrans.
Voici une fonction qui permet de récupérer la résolution d'un écran ou de tout le bureau par exemple. Très utile afin de gérer les multi-screens :
► Afficher le texteFonction 'getResolution( )'
Code : Tout sélectionner
; #FUNCTION# ====================================================================================================================
; Name...........: getResolution
; Description ...: Returns the dimension of the specified display and time without a possible gap.
; Syntax.........: getResolution( [$display] )
; Parameters ....: $display - string as a RegExp. By default ($display=""), the dimenseion of the whole display is returned
; Return values .: Success - Returns an array of 4 elements
; |$array[0] - X coord of the top-left corner for the display
; |$array[1] - Y coord of the top-left corner for the display
; |$array[2] - Width of the top-left corner for the display
; |$array[3] - Height of the top-left corner for the display
; |@extended - Number of screens for the display (not zero)
; Failure - @extended is set to zero
; Author ........: ZDS
; Modified.......:
; Related .......:
; ===============================================================================================================================
Func getResolution($display="")
Local $res[4] = [0,0,0,0], $i = 0, $n = 0
While 1
Local $struct = DllStructCreate("dword cb;char DeviceName[32];char DeviceString[128];dword StateFlags;char DeviceID[128];char DeviceKey[128]")
DllStructSetData($struct, "cb", DllStructGetSize($struct))
Local $displays = DllCall("user32.dll", "int", "EnumDisplayDevices", "ptr", 0, "dword", $i, "ptr", DllStructGetPtr($struct), "dword", 0)
If Not $displays[0] Then ExitLoop
If StringRegExp(DllStructGetData($struct, "DeviceName"),$display) And Not BitAND(DllStructGetData($struct, "StateFlags"), 0x00000008) Then
Local $infos = DllStructCreate("char dmDeviceName[32];ushort dmSpecVersion;ushort dmDriverVersion;short dmSize;" & _
"ushort dmDriverExtra;dword dmFields;long x;long y;dword dmDisplayOrientation;dword dmDisplayFixedOutput;" & _
"short dmColor;short dmDuplex;short dmYResolution;short dmTTOption;short dmCollate;" & _
"byte dmFormName[32];ushort LogPixels;dword dmBitsPerPel;int dmPelsWidth;dword dmPelsHeight;" & _
"dword dmDisplayFlags;dword dmDisplayFrequency")
DllStructSetData($infos, "dmSize", DllStructGetSize($infos))
$displays = DllCall("user32.dll", "int", "EnumDisplaySettings", "str", DllStructGetData($struct, "DeviceName"), "dword", -1, "ptr", DllStructGetPtr($infos))
Local $x0 = DllStructGetData($infos, "x"), $y0 = DllStructGetData($infos, "y"), $w = DllStructGetData($infos, "dmPelsWidth"), $h = DllStructGetData($infos, "dmPelsHeight")
Local $x1 = $x0 + $w, $y1 = $y0 + $h
If $w > 0 And $h > 0 Then
If $res[0] > $x0 Then $res[0] = $x0
If $res[1] > $y0 Then $res[1] = $y0
If $res[2] < $x1 Then $res[2] = $x1
If $res[3] < $y1 Then $res[3] = $y1
$n += 1
EndIf
EndIf
$i += 1
WEnd
$res[2] = $res[2]-$res[0]
$res[3] = $res[3]-$res[1]
SetExtended($n)
Return $res
EndFunc
► Afficher le texteExemple pour la fonction 'getResolution( )'
Code : Tout sélectionner
#Include <Array.au3>
Local $resolution = getResolution()
_ArrayDisplay($resolution, "Tout - "&@extended&" écran(s) trouvé(s)")
Local $resolution1 = getResolution("\w1$")
_ArrayDisplay($resolution1, "N°1 - "&@extended&" écran(s) trouvé(s)")
Local $resolution2 = getResolution("\w2$")
_ArrayDisplay($resolution2, "N°2 - "&@extended&" écran(s) trouvé(s)")
Local $resolution3 = getResolution("\w3$")
_ArrayDisplay($resolution3, "N°3 - "&@extended&" écran(s) trouvé(s)")
EDIT: [Confirmé] Correction par rapport à certains systèmes qui considèrent une sortie non connectée comme un écran possible, et faussent le nombre d'écrans.