Jump to content

Dual monitor configuration


Recommended Posts

Maybe _WinAPI_EnumDisplayMonitors can help you :

 - In extended mode, the return array contains 2 lines (2 monitors)

 - In Duplicate mode, the return array contains just 1 line

#include <WinAPIGdi.au3>




Local $objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\" & @ComputerName & "\root\cimv2")
Local $colMonitors = $objWMIService.ExecQuery ("Select * from Win32_DesktopMonitor Where Availability=3", "WQL", 0x10 + 0x20)

If NOT IsObj($colMonitors) Then Exit

Local $iCount = 0
For $oMonitor In $colMonitors
    $iCount += 1
Next
MsgBox(0, "", "Number of monitors : " & $iCount)

$aMonitor = _WinAPI_EnumDisplayMonitors()
If @error Then Exit

If $aMonitor[0][0] > 1 Then
    MsgBox(0, "", "extended mode")
Else
    MsgBox(0, "", "duplicate mode")
EndIf
Link to comment
Share on other sites

>try this

here is my contribution...

;http://msdn.microsoft.com/en-us/library/aa394199(v=vs.85).aspx
#include-once
#include <Date.au3>
#include <String.au3>
#include <Array.au3>
;~ #include <object_dump.au3>
Global $ERROR = "@error"
Local $oo = oWIN_Monitor()
dump($oo)


Func oWIN_Monitor()
    If Not IsDeclared("ERROR") Then Local $ERROR = "@error"
    Local $objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate,authenticationLevel=Pkt}!\\" & @ComputerName & "\root\wmi")
    Local $arrName = StringSplit("InstanceName,ManufacturerName,ManufacturerNameLength,ProductCodeID,SerialNumberID,WeekOfManufacture,YearOfManufacture,UserFriendlyName,UserFriendlyNameLength", ",", 2)
    Local $oo = ObjCreate("Scripting.Dictionary")
    Local $oTemp, $str
    Local $colItems = $objWMIService.ExecQuery("SELECT * FROM WmiMonitorID", "WQL", 0x10 + 0x20)
    If IsObj($colItems) Then
        For $objItem In $colItems
            $oTemp = ObjCreate("Scripting.Dictionary")

            $str = $objItem.InstanceName
            $str = $str ? $str : $ERROR
            $oTemp.Add("InstanceName", $str)

            $str = oManufacturerMonitor(StringFromASCIIArray($objItem.ManufacturerName, 0, Default, 2))
            $str = $str ? $str : $ERROR
            $oTemp.Add("ManufacturerName", $str)

            $str = StringFromASCIIArray($objItem.SerialNumberID, 0, Default, 2)
            $str = $str ? $str : $ERROR
            $oTemp.Add("SerialNumberID", $str)

            $str = StringFromASCIIArray($objItem.UserFriendlyName, 0, Default, 2)
            $str = $str ? $str : $ERROR
            $oTemp.Add("UserFriendlyName", $str)

            $str = StringFromASCIIArray($objItem.ProductCodeID, 0, Default, 2)
            $str = $str ? $str : $ERROR
            $oTemp.Add("ProductCodeID", $str)

            $str = _DateFromWeekNumber($objItem.YearOfManufacture, $objItem.WeekOfManufacture)
            $str = $str ? $str : $ERROR
            $oTemp.Add("DateOfManufacture", $str)
            $oo.Add($oo.Count + 1, $oTemp)
        Next
    EndIf
    Return $oo
EndFunc   ;==>oWIN_Monitor






Func _DateFromWeekNumber($iYear, $iWeekNum)
;~  http://www.autoitscript.com/forum/topic/157146-get-date-from-week-number/
    Local $Date, $sFirstDate = _DateToDayOfWeek($iYear, 1, 1)
    If $sFirstDate < 6 Then
        $Date = _DateAdd("D", 2 - $sFirstDate, $iYear & "/01/01")
    ElseIf $sFirstDate = 6 Then
        $Date = _DateAdd("D", $sFirstDate - 3, $iYear & "/01/01")
    ElseIf $sFirstDate = 7 Then
        $Date = _DateAdd("D", $sFirstDate - 5, $iYear & "/01/01")
    EndIf
    Local $aDate = StringSplit($Date, "/", 2)
    Return _DateAdd("w", $iWeekNum - 1, $aDate[0] & "/" & $aDate[1] & "/" & $aDate[2])
EndFunc   ;==>_DateFromWeekNumber

Func oManufacturerMonitor($input = 0)
    Local $oo = ObjCreate("Scripting.Dictionary")
    $oo.Add("AAC", "AcerView")
    $oo.Add("ACR", "Acer")
    $oo.Add("AOC", "AOC")
    $oo.Add("AIC", "AG Neovo")
    $oo.Add("APP", "Apple Computer")
    $oo.Add("AST", "AST Research")
    $oo.Add("AUO", "Asus")
    $oo.Add("BNQ", "BenQ")
    $oo.Add("CMO", "Acer")
    $oo.Add("CPL", "Compal")
    $oo.Add("CPQ", "Compaq")
    $oo.Add("CPT", "Chunghwa Pciture Tubes, Ltd.")
    $oo.Add("CTX", "CTX")
    $oo.Add("DEC", "DEC")
    $oo.Add("DEL", "Dell")
    $oo.Add("DPC", "Delta")
    $oo.Add("DWE", "Daewoo")
    $oo.Add("EIZ", "EIZO")
    $oo.Add("ELS", "ELSA")
    $oo.Add("ENC", "EIZO")
    $oo.Add("EPI", "Envision")
    $oo.Add("FCM", "Funai")
    $oo.Add("FUJ", "Fujitsu")
    $oo.Add("FUS", "Fujitsu-Siemens")
    $oo.Add("GSM", "LG Electronics")
    $oo.Add("GWY", "Gateway 2000")
    $oo.Add("HEI", "Hyundai")
    $oo.Add("HIT", "Hyundai")
    $oo.Add("HSL", "Hansol")
    $oo.Add("HTC", "Hitachi/Nissei")
    $oo.Add("HWP", "Hewlett-Packard")
    $oo.Add("IBM", "IBM")
    $oo.Add("ICL", "Fujitsu ICL")
    $oo.Add("IVM", "Iiyama")
    $oo.Add("KDS", "Korea Data Systems")
    $oo.Add("LEN", "Lenovo")
    $oo.Add("LGD", "Asus")
    $oo.Add("LPL", "Fujitsu")
    $oo.Add("MAX", "Belinea")
    $oo.Add("MEI", "Panasonic")
    $oo.Add("MEL", "Mitsubishi Electronics")
    $oo.Add("MS_", "Panasonic")
    $oo.Add("NAN", "Nanao")
    $oo.Add("NEC", "NEC")
    $oo.Add("NOK", "Nokia Data")
    $oo.Add("NVD", "Fujitsu")
    $oo.Add("OPT", "Optoma")
    $oo.Add("PHL", "Philips")
    $oo.Add("REL", "Relisys")
    $oo.Add("SAN", "Samsung")
    $oo.Add("SAM", "Samsung")
    $oo.Add("SBI", "Smarttech")
    $oo.Add("SGI", "SGI")
    $oo.Add("SNY", "Sony")
    $oo.Add("SRC", "Shamrock")
    $oo.Add("SUN", "Sun Microsystems")
    $oo.Add("SEC", "Hewlett-Packard")
    $oo.Add("TAT", "Tatung")
    $oo.Add("TOS", "Toshiba")
    $oo.Add("TSB", "Toshiba")
    $oo.Add("VSC", "ViewSonic")
    $oo.Add("ZCM", "Zenith")
    $oo.Add("UNK", "Unknown")
    $oo.Add("_YV", "Fujitsu")

    If IsDeclared("input") And $input Then
        If $oo.Exists($input) Then
            Return $oo.Item($input)
        Else
            Return "@UNKNOW[" & $input & "]"
        EndIf
    Else
        Return $oo
    EndIf
EndFunc   ;==>oManufacturerMonitor


Func dump($oo, $key = "", $iIdent = 0)
    Local $iTab = 4
    Local $sKeys
    If IsDictionary($oo) Then
        $sKeys = $oo.Keys
        For $each In $sKeys
            If IsDictionary($oo.Item($each)) Or IsArray($oo.Item($each)) Then
                ConsoleWrite(($iIdent == 0 ? "" : (_StringRepeat(" ", $iIdent))) & $each & "{" & @LF)
                dump($oo.Item($each), ($key == "" ? "" : $key & ".") & $each, $iTab + $iIdent)
                ConsoleWrite(($iIdent == 0 ? "" : (_StringRepeat(" ", $iIdent))) & "}" & @LF)
            Else
                ConsoleWrite(($iIdent == 0 ? "" : (_StringRepeat(" ", $iIdent))) & ($key == "" ? "" : $key & ".") & $each & " = " & $oo.Item($each) & @LF)
            EndIf
        Next
    Else
        If IsArray($oo) Then
            Switch UBound($oo, 0)
                Case 1
                    For $ii = 0 To UBound($oo, 1) - 1
                        If IsDictionary($oo[$ii]) Or IsArray($oo[$ii]) Then
                            dump($oo[$ii], $key & "[" & $ii & "]", $iTab + $iIdent)
                        Else
                            ConsoleWrite(($iIdent == 0 ? "" : (_StringRepeat(" ", $iIdent))) & ($key == "" ? "" : $key & "[") & $ii & "] = " & $oo[$ii] & @LF)
                        EndIf
                    Next
                Case 2
                    For $ii = 0 To UBound($oo, 1) - 1
                        For $jj = 0 To UBound($oo, 2) - 1
                            If IsDictionary($oo[$ii][$jj]) Or IsArray($oo[$ii][$jj]) Then
                                dump($oo[$ii][$jj], $key & "[" & $ii & "][" & $jj & "]", $iTab + $iIdent)
                            Else
                                ConsoleWrite(($iIdent == 0 ? "" : (_StringRepeat(" ", $iIdent))) & ($key == "" ? "" : $key & "[") & $ii & "][" & $jj & "] = " & $oo[$ii][$jj] & @LF)
                            EndIf
                        Next
                    Next
            EndSwitch
        Else

        EndIf
    EndIf
EndFunc   ;==>dump

Func IsDictionary($oo = Null)
    If Not IsObj($oo) Or Not (ObjName($oo, 2) == "Scripting.Dictionary") Then Return 0
;~  If Not (ObjName($oo, 2) == "Scripting.Dictionary") Then Return 0
    Return 1
EndFunc   ;==>IsDictionary
Edited by Detefon

Visit my repository

Link to comment
Share on other sites

#include <WinAPIGdi.au3>

#include <WindowsConstants.au3>

Const $monitor_count = _WinAPI_GetSystemMetrics($SM_CMONITORS)

MsgBox(0, '', "Number of monitors : " & $monitor_count)

Const $aMonitor = _WinAPI_EnumDisplayMonitors()

If @error Then Exit

If $aMonitor[0][0] > 1 Then
  MsgBox(0, "", "extended mode")
Else
  MsgBox(0, "", "duplicate mode")
EndIf

Link to comment
Share on other sites

Well, Windows has these options for multiple monitors: - Duplicate these displays - Extend these displays - Show desktop only on 1 - Show desktop only on 2 I need to know which option is being used. There might be a registry entry holding that information, but I couldn't find it.

[HKEY_LOCAL_MACHINESYSTEMCurrentControlSetControlGraphicsDriversConnectivity]

 

App: Au3toCmd              UDF: _SingleScript()                             

Link to comment
Share on other sites

@Exit: That registry key includes a lot of subkeys. I looked at a few of them and I didn't find any data value that show which configuration is being used.

http://lmgtfy.com/?q=hkey_local_machine+system+currentcontrolset+control+graphicsdrivers+connectivity

App: Au3toCmd              UDF: _SingleScript()                             

Link to comment
Share on other sites

@Exit: We all know how to google ...

 

And I googled it for you and found explanaition of the reg entries.

Here is my configuration. See my comments.

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\GraphicsDrivers\Configuration]

; My config is a Medion as first and a Sony as second monitor
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\GraphicsDrivers\Configuration\MED360516843009_00_07D9_F4+SNY13903491177_0D_07D4_E1^BA4B4E96467A583E200772AC5B538500]
"SetId"="MED360516843009_00_07D9_F4+SNY13903491177_0D_07D4_E1"
"Timestamp"=hex(b):00,f7,bf,f9,fc,d5,cf,01

; Key 00 is monitor number 1
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\GraphicsDrivers\Configuration\MED360516843009_00_07D9_F4+SNY13903491177_0D_07D4_E1^BA4B4E96467A583E200772AC5B538500\00]
; screensize in hex
"PrimSurfSize.cx"=dword:00000780
"PrimSurfSize.cy"=dword:00000438
"Stride"=dword:00001e00
"PixelFormat"=dword:00000015
"ColorBasis"=dword:00000002
; x or y not 0 means "This is the desktop expansion monitor 
"Position.cx"=dword:00000500
"Position.cy"=dword:00000000


; Key 01 is monitor number 2
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\GraphicsDrivers\Configuration\MED360516843009_00_07D9_F4+SNY13903491177_0D_07D4_E1^BA4B4E96467A583E200772AC5B538500\01]
; screensize in hex
"PrimSurfSize.cx"=dword:00000500
"PrimSurfSize.cy"=dword:00000400
"Stride"=dword:00001400
"PixelFormat"=dword:00000015
"ColorBasis"=dword:00000002
; x/y = 0 means "This is the desktop monitor with START button and SYSTEM TRAY"
"Position.cx"=dword:00000000
"Position.cy"=dword:00000000

Enough spoonfeeding ?

App: Au3toCmd              UDF: _SingleScript()                             

Link to comment
Share on other sites

@Exit: Thanks, but, no thanks. Your response does not address the question: How to find, in a dual display setup, which of these options: 1st display only, 2nd display only, extend desktop or duplicate desktop is being used. By the way, recent Windows versions, have system tray on both 1st and 2nd displays.

Link to comment
Share on other sites

pCurrentTopologyId parameter of QueryDisplayConfig function points to a DISPLAYCONFIG_TOPOLOGY_ID enumeration, it tells you if the monitor is extend or duplicate (clone). It is available only in windows 7 (and maybe in higher OS)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...