Jump to content

Detect Windows Monitor Autodetection


Recommended Posts

Hi,

how can i react on the moment, when windows auto detect hdmi monitor connection od disconnection.

in this moment we always get our display in autoit programs running puzzled.

it's a short moment, all other monitors turn black for a moment until the detection is finished.

thanks for any idea, how to detect this moment and react on it.

cheers mike

Link to comment
Share on other sites

You could have a play about with this?

Global $g_oWMI
Global $g_aCollection

$g_oWMI = ObjGet('winmgmts:\\localhost\root\CIMV2')
$g_aCollection = $g_oWMI.ExecQuery('SELECT * FROM Win32_DesktopMonitor', 'WQL', (0x10 + 0x20))

If IsObj($g_aCollection) Then
    For $oItem In $g_aCollection
        ConsoleWrite(StringFormat('Device ID: %s, Availability: %s', $oItem.DeviceID, $oItem.Availability) & @CRLF)
    Next
EndIf

Output (for me):

Quote

Device ID: DesktopMonitor1, Availability: 3
Device ID: DesktopMonitor2, Availability: 8

Availability values:

Quote

Other (1)

 

 

Unknown (2)

 

 

Running/Full Power (3)

Running or Full Power

 

Warning (4)

 

 

In Test (5)

 

 

Not Applicable (6)

 

 

Power Off (7)

 

 

Off Line (8)

 

 

Off Duty (9)

 

 

Degraded (10)

 

 

Not Installed (11)

 

 

Install Error (12)

 

 

Power Save - Unknown (13)

The device is known to be in a power save mode, but its exact status is unknown.

 

Power Save - Low Power Mode (14)

The device is in a power save state but still functioning, and may exhibit degraded performance.

 

Power Save - Standby (15)

The device is not functioning, but could be brought to full power quickly.

 

Power Cycle (16)

 

 

Power Save - Warning (17)

The device is in a warning state, though also in a power save mode.

 

Paused (18)

The device is paused.

 

Not Ready (19)

The device is not ready.

 

Not Configured (20)

The device is not configured.

 

Quiesced (21)

The device is quiet.

As you can see for me, DesktopMonitor1 is Running/Full power and DesktopMonitor2 is Off Line.

I would assume during that brief moment the Availability would return Off Line (8).

For more information, see Win32_DesktopMonitor class.

Link to comment
Share on other sites

Check out this from @Xenobiologist here too:

; Generated by AutoIt Scriptomatic

$wbemFlagReturnImmediately = 0x10
$wbemFlagForwardOnly = 0x20
$colItems = ""
$strComputer = "localhost"

Sleep(5000)

$Output=""
$Output = $Output & "Computer: " & $strComputer  & @CRLF
$Output = $Output & "==========================================" & @CRLF
$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")
$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_DesktopMonitor", "WQL", _
                                        $wbemFlagReturnImmediately + $wbemFlagForwardOnly)

If IsObj($colItems) then
   For $objItem In $colItems
    $Output = $Output & "Availability: " & $objItem.Availability & @CRLF
    $Output = $Output & "Bandwidth: " & $objItem.Bandwidth & @CRLF
    $Output = $Output & "Caption: " & $objItem.Caption & @CRLF
    $Output = $Output & "ConfigManagerErrorCode: " & $objItem.ConfigManagerErrorCode & @CRLF
    $Output = $Output & "ConfigManagerUserConfig: " & $objItem.ConfigManagerUserConfig & @CRLF
    $Output = $Output & "CreationClassName: " & $objItem.CreationClassName & @CRLF
    $Output = $Output & "Description: " & $objItem.Description & @CRLF
    $Output = $Output & "DeviceID: " & $objItem.DeviceID & @CRLF
    $Output = $Output & "DisplayType: " & $objItem.DisplayType & @CRLF
    $Output = $Output & "ErrorCleared: " & $objItem.ErrorCleared & @CRLF
    $Output = $Output & "ErrorDescription: " & $objItem.ErrorDescription & @CRLF
    $Output = $Output & "InstallDate: " & WMIDateStringToDate($objItem.InstallDate) & @CRLF
    $Output = $Output & "IsLocked: " & $objItem.IsLocked & @CRLF
    $Output = $Output & "LastErrorCode: " & $objItem.LastErrorCode & @CRLF
    $Output = $Output & "MonitorManufacturer: " & $objItem.MonitorManufacturer & @CRLF
    $Output = $Output & "MonitorType: " & $objItem.MonitorType & @CRLF
    $Output = $Output & "Name: " & $objItem.Name & @CRLF
    $Output = $Output & "PixelsPerXLogicalInch: " & $objItem.PixelsPerXLogicalInch & @CRLF
    $Output = $Output & "PixelsPerYLogicalInch: " & $objItem.PixelsPerYLogicalInch & @CRLF
    $Output = $Output & "PNPDeviceID: " & $objItem.PNPDeviceID & @CRLF
    $strPowerManagementCapabilities = $objItem.PowerManagementCapabilities(0)
    $Output = $Output & "PowerManagementCapabilities: " & $strPowerManagementCapabilities & @CRLF
    $Output = $Output & "PowerManagementSupported: " & $objItem.PowerManagementSupported & @CRLF
    $Output = $Output & "ScreenHeight: " & $objItem.ScreenHeight & @CRLF
    $Output = $Output & "ScreenWidth: " & $objItem.ScreenWidth & @CRLF
    $Output = $Output & "Status: " & $objItem.Status & @CRLF
    $Output = $Output & "StatusInfo: " & $objItem.StatusInfo & @CRLF
    $Output = $Output & "SystemCreationClassName: " & $objItem.SystemCreationClassName & @CRLF
    $Output = $Output & "SystemName: " & $objItem.SystemName & @CRLF
    if Msgbox(1,"WMI Output",$Output) = 2 then ExitLoop
    $Output=""
   Next
Else
   Msgbox(0,"WMI Output","No WMI Objects Found for class: " & "Win32_DesktopMonitor" )
Endif


Func WMIDateStringToDate($dtmDate)

    Return (StringMid($dtmDate, 5, 2) & "/" & _
    StringMid($dtmDate, 7, 2) & "/" & StringLeft($dtmDate, 4) _
    & " " & StringMid($dtmDate, 9, 2) & ":" & StringMid($dtmDate, 11, 2) & ":" & StringMid($dtmDate,13, 2))
EndFunc

 

Link to comment
Share on other sites

Hi Luke,

thanks for the reply, which is fine for checking the state of monitors.

But in my case I had the problem,

when the autodetection of windows7 detects hdmi on/off,

it changes the size of one of my windows.

this window is for displaying info,

a small window like a dialogbox.

it would suddenly spread over the whole screen during this autodetection.

for this problem i found a solution:

original code was:

$hStyle = $WS_CAPTION
$hExStyle = BitOR($WS_EX_DLGMODALFRAME, $WS_EX_TOPMOST)
$hGUI = GUICreate($sTitle, $iWidth, $iHeight, $iLeft, $iTop, $hStyle, $hExStyle, 0)

new code is:

$hWnd = GUICreate("")
$hStyle = BitOR($WS_CAPTION, $WS_POPUP)
$hExStyle = BitOR($WS_EX_DLGMODALFRAME, $WS_EX_TOPMOST)
$hGUI = GUICreate($sTitle, $iWidth, $iHeight, $iLeft, $iTop, $hStyle, $hExStyle, $hWnd)

Now the window keeps in it's position and size during  windows7 autodetection.

Thanks for your code anyway.

It's fine for detection monitors and setup individual screen sets.

Cheers mike

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...