Jump to content

Return all possible monitor modes


 Share

Recommended Posts

Hi all,

there's a small tool called displaychanger from 12noon (http://www.12noon.com/displaychanger.htm) which can switch to a specific resolution or refresh rate. With the option dccmd.exe -listmodes it also returns all available modes which would help me a lot for a script. The problem for me is that I cannot access the return value that the displaychanger gives back.

Does anybode here have an idea if it is possible. I did not find an answer via search but perhaps somebody here has made experience with this tool

Thanks and Regards,

B

Link to comment
Share on other sites

I'm not familiar with that tool, but there appears to be an API call you can use to retrieve the info. http://msdn.microsoft.com/en-us/library/dd162611%28v=vs.85%29.aspx

Unfortunately for both of us I'm not too clever when it comes to this stuff so I'm stuck at the first step, which is converting a documented Struct into AutoIt language.

Can anyone shed some light on provide an exmaple on how to create this struct in AutoIt, particularly the Union?

Edited by spudw2k
Link to comment
Share on other sites

I asked about unions a while ago, it's an interesting read:

In summary, the union must be the largest size, but you can use the smaller one as long as you add enough empty values as padding. You are very lucky in that the big union is the same size on both sides, so you don't need padding. That's still a beast of of a struct. I made a start and then gave up:

Global Const $tagDEVMODE_1 = "TCHAR DeviceName[" & $CCHDEVICENAME & "]; WORD  SpecVersion; WORD  DriverVersion; WORD  Size; " & _
    "WORD  DriverExtra; DWORD Fields; short Orientation; short PaperSize; short PaperLength; short PaperWidth; short Scale; " & _ 
    "short Copies; short DefaultSource; short PrintQuality;" & _ 
    "short Color; short Duplex; short YResolution; short TTOption; short Collate; TCHAR FormName[" & $CCHFORMNAME & "];" & _ 
    "WORD  LogPixels; DWORD BitsPerPel; DWORD PelsWidth; DWORD PelsHeight; DWORD DisplayFlags; DWORD DisplayFrequency; " & _ 
    "DWORD ICMMethod; DWORD ICMIntent; DWORD MediaType; DWORD DitherType; DWORD Reserved1; DWORD Reserved2; DWORD PanningWidth; DWORD PanningHeight;"
  
Global Const $tagDEVMODE_2 = "TCHAR DeviceName[" & $CCHDEVICENAME & "]; WORD  SpecVersion; WORD  DriverVersion; WORD  Size; " & _
    "WORD  DriverExtra; DWORD Fields; " & $tagPOINTL & "; DWORD  DisplayOrientation; DWORD  DisplayFixedOutput;" & _
    "short Color; short Duplex; short YResolution; short TTOption; short Collate; TCHAR FormName[" & $CCHFORMNAME & "];" & _ 
    "WORD  LogPixels; DWORD BitsPerPel; DWORD PelsWidth; DWORD PelsHeight; DWORD DisplayFlags; DWORD DisplayFrequency; " & _ 
    "DWORD ICMMethod; DWORD ICMIntent; DWORD MediaType; DWORD DitherType; DWORD Reserved1; DWORD Reserved2; DWORD PanningWidth; DWORD PanningHeight;"
Link to comment
Share on other sites

How about getting all modes through WMI?

#include <Array.au3>


Global $Settings[1]
; Generated by AutoIt Scriptomatic January 07, 2011

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

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

If IsObj($colItems) then
   For $objItem In $colItems
;~       $Output &= "Element: " & $objItem.Element & @CRLF
      $Output = $objItem.Setting
        $TrimOut = StringSplit ($Output , "=" , 2)

$fmtSetting = StringRegExpReplace ($TrimOut[1] , '"' , "")

 _ArrayAdd ($Settings , $fmtSetting)

  Next

  _ArrayDelete ($Settings, 0)
 _ArrayDisplay ($Settings)


Else
   Msgbox(0,"WMI Output","No WMI Objects Found for class: " & "Win32_VideoSettings" )
Endif

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Link to comment
Share on other sites

Hi there,

thank you all very much fopr answering.

@Mat: Wow thats huge. But unfortunatelly I do not really know how handling this.

@WMI: Intersting. But your code does not display anything. This probably has to do with differnet OS Versions (I use W7 Ultimate GErman), I guess.

The point why I wanna using this tool is because it is done by developpers who know what they are doing. Unfortunatelly I'm not one of these :-) So this would be my choice.

I tried it with

dim $monitornumber, $Switchwidth, $Switchheight, $Switchrefresh

$monitornumber = 1
$Switchwidth = 1920
$Switchheight = 1080
$Switchrefresh = 60

run('dc.exe -quiet -monitor="\\.\DISPLAY' & $monitornumber &'"' & " -width=" & $Switchwidth & " -height=" & $Switchheight & " -refresh=" & $Switchrefresh,)

This perfectly works :-) for switching the resolution etc.

Then I tried:

$modes = run('dc.exe -quiet -listmodes
msgbox(4096,"",$modes)

which returns an number. Anybody an idea?

Regards,

Alex

Link to comment
Share on other sites

I was able to get something that may work for you using the dccmd version of the tool. For some reason I could only write the output file with a batch file...normally, I could just use RunWait and redirect to output to a file, but this program did not let that happen. Anyways, once the output is redirected to a file, I replaced all the Tabs with commas (first Array Display) and then made a new array with the "Width/Heigth/Depth/Refresh" in their own columns. You should be able to get where you want to go from here.

#include <File.au3>
#include <Array.au3>

$oFile = _CreateFile()
If Not FileExists($oFile) Then Exit
$String = StringRegExpReplace(FileRead($oFile), '[\t]+', ',')   ;replace all tabs in output file with commas

$Array = StringSplit($String, @LF)
If IsArray($Array) Then _ArrayDisplay($Array, 'Original File with commas')
Local $MultiArray[$Array[0]][4]
For $i = 1 To $Array[0]
    If Not $Array[$i] Then ContinueLoop
    Local $TempArray = StringSplit($Array[$i], ',', 2)
    For $z = 0 To UBound($TempArray) - 1
        $MultiArray[$i][$z] = $TempArray[$z]
    Next
Next
$MultiArray[0][0] = UBound($MultiArray, 1) - 1
If IsArray($MultiArray) Then _ArrayDisplay($MultiArray, 'Width/Heigth/Depth/Refresh')

Func _CreateFile()
    $Executable = @ProgramFilesDir & '\12noon Display Changer\dccmd.exe'
    If Not FileExists($Executable) Then Exit MsgBox(270352, 'Fatal Error', 'Cannot find:' & @LF & $Executable)
    $S_TempFile = _TempFile('', '', '.txt')
    $S_TempBatch = _TempFile('', '', '.bat')
    $bString = FileGetShortName($Executable) & ' -listmodes > ' & $S_TempFile
    $TempBatch = FileOpen($S_TempBatch, 2)
    FileWrite($TempBatch, $bString)
    FileClose($TempBatch)
    RunWait($S_TempBatch, '', @SW_HIDE)
    Return $S_TempFile
EndFunc   ;==>_CreateFile
Link to comment
Share on other sites

Hi,

at first: Thank you so much for your help and support. Didn't expect that :-)

And yes it works, I get an array out that includes all the possible values.

So the first big step is done and I can continue with my script. Thank you so much for this.

Regards,

Alex

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