Sign in to follow this  
Followers 0
Berny

Setting Desktop Resolutions With Autoit?

8 posts in this topic

Hello, I have just found out about Autoit 3 days ago, and I think it is subperb. My friend recommended it to me.

I've been playing with it and I think I've gotten further then I could in c++, and vb.. Now I'm trying to create a script that will set the screen resolution by pressing a button... But it doesn't workd :think: anyways heres the script.

#include <GUIConstants.au3>
GuiCreate("res", 394, 380,-1, -1)
$supersmall= GUICtrlCreateButton("1218x1024",50,50,200,15)
$small= GUICtrlCreateButton("1280x768",50,80,200,15)
$medium= GUICtrlCreateButton("1152x864",50,100,200,15)
$normal= GUICtrlCreateButton("1024x964",50,120,200,15)
$huge= GUICtrlCreateButton("800x600",50,140,200,15)
GUISetState()

while 1
    sleep(200)
    $msg = GUIGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE
        exitloop
    case $msg = $supersmall
        _1218()
    case $msg = $small
        _1280()
    case $msg = $medium
        _1152()
    case $msg = $normal
        _1024()
    case $msg = $huge
        _800()
 If $msg = $GUI_EVENT_CLOSE Then ExitLoop
 EndSelect
WEnd

func _1218()
RegRead("HKEY_CURRENT_USER","SessionInformation")
Return @DesktopWidth & @DesktopHeight
;RegWrite("HKEY_CURRENT_USER","SessionInformation")
EndFunc

func _1280()
RegRead("HKEY_CURRENT_USER","SessionInformation")
Return @DesktopWidth & @DesktopHeight
;RegWrite("HKEY_CURRENT_USER","SessionInformation")
EndFunc

func _1152()
RegRead("HKEY_CURRENT_USER","SessionInformation")
Return @DesktopWidth & @DesktopHeight
;RegWrite("HKEY_CURRENT_USER","SessionInformation")
EndFunc

func _1024()
RegRead("HKEY_CURRENT_USER","SessionInformation")
Return @DesktopWidth& @DesktopHeight
;RegWrite("HKEY_CURRENT_USER","SessionInformation")
EndFunc

func _800()
RegRead("HKEY_CURRENT_USER","SessionInformation")
Return @DesktopWidth & @DesktopHeight
;RegWrite("HKEY_CURRENT_USER","SessionInformation")
EndFunc

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Hello, I have just found out about Autoit 3 days ago, and I think it is subperb. My friend recommended it to me.

I've been playing with it and I think I've gotten further then I could in c++, and vb.. Now I'm trying to create a script that will set the screen resolution by pressing a button... But it doesn't workd :think: anyways heres the script.

CODE
#include <GUIConstants.au3>

GuiCreate("res", 394, 380,-1, -1)

$supersmall= GUICtrlCreateButton("1218x1024",50,50,200,15)

$small= GUICtrlCreateButton("1280x768",50,80,200,15)

$medium= GUICtrlCreateButton("1152x864",50,100,200,15)

$normal= GUICtrlCreateButton("1024x964",50,120,200,15)

$huge= GUICtrlCreateButton("800x600",50,140,200,15)

GUISetState()

while 1

sleep(200)

$msg = GUIGetMsg()

Select

Case $msg = $GUI_EVENT_CLOSE

exitloop

case $msg = $supersmall

_1218()

case $msg = $small

_1280()

case $msg = $medium

_1152()

case $msg = $normal

_1024()

case $msg = $huge

_800()

If $msg = $GUI_EVENT_CLOSE Then ExitLoop

EndSelect

WEnd

func _1218()

RegRead("HKEY_CURRENT_USER","SessionInformation")

Return @DesktopWidth & @DesktopHeight

;RegWrite("HKEY_CURRENT_USER","SessionInformation")

EndFunc

func _1280()

RegRead("HKEY_CURRENT_USER","SessionInformation")

Return @DesktopWidth & @DesktopHeight

;RegWrite("HKEY_CURRENT_USER","SessionInformation")

EndFunc

func _1152()

RegRead("HKEY_CURRENT_USER","SessionInformation")

Return @DesktopWidth & @DesktopHeight

;RegWrite("HKEY_CURRENT_USER","SessionInformation")

EndFunc

func _1024()

RegRead("HKEY_CURRENT_USER","SessionInformation")

Return @DesktopWidth& @DesktopHeight

;RegWrite("HKEY_CURRENT_USER","SessionInformation")

EndFunc

func _800()

RegRead("HKEY_CURRENT_USER","SessionInformation")

Return @DesktopWidth & @DesktopHeight

;RegWrite("HKEY_CURRENT_USER","SessionInformation")

EndFunc

Check out thread #19324 for how to do it with an object call.

On your script, you have some things that don't look right to me (doesn't mean they're wrong, necesarily):

There's no need for the IF statement for $GUI_EVENT_CLOSE in your while loop. Just make it one more CASE, which was already there, so it's redundant anyway:

while 1
    sleep(200)
    $msg = GUIGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE
        exitloop
    case $msg = $supersmall
        _1218()
    case $msg = $small
        _1280()
    case $msg = $medium
        _1152()
    case $msg = $normal
        _1024()
    case $msg = $huge
        _800()
 EndSelect
WEnd

You commented out the RegWrite() functions, but the location of your Return statements prevents them from being executed anyway. The function exits at Return:

func _800()
    RegRead("HKEY_CURRENT_USER","SessionInformation")
    RegWrite("HKEY_CURRENT_USER","SessionInformation")
    Return @DesktopWidth & @DesktopHeight
EndFunc

The other problem (as you may have noticed) is that changing those reg keys doesn't change the desktop like you want, hence the link to thread #19324.

Hope that helps! :(

Edited by PsaltyDS

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

I've been playing with it and I think I've gotten further then I could in c++, and vb.. Now I'm trying to create a script that will set the screen resolution by pressing a button... But it doesn't workd tongue.gif anyways heres the script.

This has been done before... But foremost, your going to have issues in the future if you call functions that don't do anything. I'll see if I can find the thread.

Edit:

PsaltyDS got me again :think:...

Edited by SmOke_N

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

Thank you PsaltyDS, for the most part I got it working except for the first top three bottoms..

Heres my new code.

#include <GUIConstants.au3>
$res= GuiCreate("res", 394, 380,-1, -1)
$supersmall= GUICtrlCreateButton("1218x1024",50,50,200,15)
$small= GUICtrlCreateButton("1280x768",50,80,200,15)
$medium= GUICtrlCreateButton("1152x864",50,100,200,15)
$normal= GUICtrlCreateButton("1024x964",50,120,200,15)
$huge= GUICtrlCreateButton("800x600",50,140,200,15)
$supersmalltxt= "1218x1024"
$smalltxt= "1280x768"
$mediumtxt= "1152x864"
$normaltxt= "1024x964"
$hugetxt= "800x600"
GUISetState(@SW_SHOW)



while 1
    $msg = GUIGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE
        exitloop
    case $msg = $supersmall
        _1218()
    case $msg = $small
        _1280()
    case $msg = $medium
        _1152()
    case $msg = $normal
        _1024()
    case $msg = $huge
        _800()
EndSelect
WEnd

func _1218()
msgbox(0,"res","setting desktop resolution to: " &$supersmalltxt)
DisplayChangeRes(1280, 1024, 32, 85)
EndFunc

func _1280()
msgbox(0,"res","setting desktop resolution to: " &$smalltxt)
DisplayChangeRes(1280, 786, 32, 85)
EndFunc

func _1152()
msgbox(0,"res","setting desktop resolution to: " &$mediumtxt)
DisplayChangeRes(1152, 864, 32, 85)
EndFunc

func _1024()
msgbox(0,"res","setting desktop resolution to: " &$normaltxt)
DisplayChangeRes(1024, 768, 32, 85)
EndFunc

func _800()
msgbox(0,"res","setting desktop resolution to: " &$hugetxt)
DisplayChangeRes(800, 600, 32, 85)
EndFunc



Func DisplayChangeRes($WIDTH, $HEIGHT, $BPP, $FREQ)
$DM_PELSWIDTH = 0x00080000
$DM_PELSHEIGHT = 0x00100000
$DM_BITSPERPEL = 0x00040000
$DM_DISPLAYFREQUENCY = 0x00400000
$CDS_TEST = 0x00000002
$CDS_UPDATEREGISTRY = 0x00000001
$DISP_CHANGE_RESTART = 1
$DISP_CHANGE_SUCCESSFUL = 0
$HWND_BROADCAST = 0xffff
$WM_DISPLAYCHANGE = 0x007E
$DEVMODE = DLLStructCreate ("byte[32];int[10];byte[32];int[6]")
$B = DllCall("user32.dll", "int", "EnumDisplaySettings", "ptr", 0, "long", 0, "ptr", DLLStructGetPtr ($DEVMODE))
If @error Then
$B = 0
Else
$B = $B[0]
EndIf
If $B <> 0 Then
DllStructSetData ($DEVMODE, 2, BitOR($DM_PELSWIDTH, $DM_PELSHEIGHT, $DM_BITSPERPEL, $DM_DISPLAYFREQUENCY), 5)
DllStructSetData ($DEVMODE, 4, $WIDTH, 2)
DllStructSetData ($DEVMODE, 4, $HEIGHT, 3)
DllStructSetData ($DEVMODE, 4, $BPP, 1)
DllStructSetData ($DEVMODE, 4, $FREQ, 5)
$B = DllCall("user32.dll", "int", "ChangeDisplaySettings", "ptr", DLLStructGetPtr ($DEVMODE), "int", $CDS_TEST)
If @error Then
$B = -1
Else
$B = $B[0]
EndIf
Select
Case $B = $DISP_CHANGE_RESTART
$DEVMODE = ""
Return 2
Case $B = $DISP_CHANGE_SUCCESSFUL
DllCall("user32.dll", "int", "ChangeDisplaySettings", "ptr", DLLStructGetPtr ($DEVMODE), "int", $CDS_UPDATEREGISTRY)
DllCall("user32.dll", "int", "SendMessage", "hwnd", $HWND_BROADCAST, "int", $WM_DISPLAYCHANGE, _
"int", $BPP, "int", $HEIGHT * 2 ^ 16 + $WIDTH)
$DEVMODE = ""
Return 1
Case Else
$DEVMODE = ""
Return $B
EndSelect
EndIf
EndFunc;==>DisplayChangeRes

Share this post


Link to post
Share on other sites

you could set a "Time out" for your message boxes

msgbox(0,"res","setting desktop resolution to: " &$supersmalltxt,4 )

shows for 4 seconds

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

@SmOke_N, I know, I couldn't find the setting in regedit so I just left them, and see if I cant get some help here.

@Valuater do you know why the top 3 buttons don't work?

Share this post


Link to post
Share on other sites

They all worked for me Berny... Are you using AutoIt Beta... I tried it with the latest.


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

@SmOke_N, I know, I couldn't find the setting in regedit so I just left them, and see if I cant get some help here.

@Valuater do you know why the top 3 buttons don't work?

Are you sure the modes are correct for your Video/Monitor combo? Can you set 1218x1024 at 85Hz manualy? those seem to be unusual aspect ratios. 1280x1024, 1024x768 and 800x600 are more typical, or is that for like a 16:9 wide screen? :think:


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
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
Sign in to follow this  
Followers 0