Jump to content

Screen Resolution Changing UDF


PartyPooper
 Share

Recommended Posts

  • 2 weeks later...
  • Replies 47
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

  • 6 months later...

Sorry to resurrect an old post again, but...

Works well on Vista sp1 as well! Nice job.

My only issue is with multiple monitors, it only affects my primary monitor. I looked at the EnumDisplaySettings on msdn and tried to switch the device call so it might also work with my secondary monitor, but no dice. Any ideas how one would go about modifying this to support an additional display device?

Thanks :)

Edited by james3mg
"There are 10 types of people in this world - those who can read binary, and those who can't.""We've heard that a million monkeys at a million keyboards could produce the complete works of Shakespeare; now, thanks to the Internet, we know that is not true." ~Robert Wilensky0101101 1001010 1100001 1101101 1100101 1110011 0110011 1001101 10001110000101 0000111 0001000 0001110 0001101 0010010 1010110 0100001 1101110
Link to comment
Share on other sites

  • 1 month later...

Same for me... please try to fix it

in response to the script not exiting/remaining in system tray.

comment out lines 62 and 63

;~              DllCall($dll, "int", "SendMessage", "hwnd", $HWND_BROADCAST, "int", $WM_DISPLAYCHANGE, _
;~                      "int", $i_BitsPP, "int", $i_Height * 2 ^ 16 + $i_Width)

that's what was making the function hang for me on Vista SP1.

on another note: for some reason Vista constantly resets my screen res to 1024x768 after it resumes from suspend mode... I wrote a script to keep in the quick launch bar until I can figure it out lol.

Link to comment
Share on other sites

  • 2 weeks later...

A modification using ChangeDisplaySettingsEx, so that specific display instances can be targeted:

From bobchernow in Multiple monitor change resolution:

OK, Here goes. This is my first UDF so be gentle.

#include-once
;===============================================================================
; Function Name:    _ChangeScreenResEx()
; Description:    Changes the current screen geometry, colour and refresh rate.
; Version:        1.0.0.0
; Parameter(s):  $i_DisplayNum - Display to change, starting at 1
;                  $i_Width - Width of the desktop screen in pixels. (horizontal resolution)
;                  $i_Height - Height of the desktop screen in pixels. (vertical resolution)
;                   $i_BitsPP - Depth of the desktop screen in bits per pixel.
;                   $i_RefreshRate - Refresh rate of the desktop screen in hertz.
; Requirement(s):   AutoIt Beta > 3.1
; Return Value(s):  On Success - Screen is adjusted, @ERROR = 0
;                  On Failure - sets @ERROR = 1
; Forum(s):      
; Author(s):        Original code - psandu.ro, PartyPooper
;                  Modifications - bobchernow
;===============================================================================
Func _ChangeScreenResEx($i_DisplayNum = 1, $i_Width = @DesktopWidth, $i_Height = @DesktopHeight, $i_BitsPP = @DesktopDepth, $i_RefreshRate = @DesktopRefresh)
    Local Const $DM_PELSWIDTH = 0x00080000
    Local Const $DM_PELSHEIGHT = 0x00100000
    Local Const $DM_BITSPERPEL = 0x00040000
    Local Const $DM_DISPLAYFREQUENCY = 0x00400000
    Local Const $CDS_TEST = 0x00000002
    Local Const $CDS_UPDATEREGISTRY = 0x00000001
    Local Const $DISP_CHANGE_RESTART = 1
    Local Const $DISP_CHANGE_SUCCESSFUL = 0
    Local Const $HWND_BROADCAST = 0xffff
    Local Const $WM_DISPLAYCHANGE = 0x007E
    If $i_Width = "" Or $i_Width = -1 Then $i_Width = @DesktopWidth; default to current setting
    If $i_Height = "" Or $i_Height = -1 Then $i_Height = @DesktopHeight; default to current setting
    If $i_BitsPP = "" Or $i_BitsPP = -1 Then $i_BitsPP = @DesktopDepth; default to current setting
    If $i_RefreshRate = "" Or $i_RefreshRate = -1 Then $i_RefreshRate = @DesktopRefresh; default to current setting
    Local $DEVMODE = DllStructCreate("byte[32];int[10];byte[32];int[6]")
    Local $s_Display
    
    $s_Display = "\\.\Display" & $i_DisplayNum
    
    Local $B = DllCall("user32.dll", "int", "EnumDisplaySettings", "ptr", 0, "int", 0, "ptr", DllStructGetPtr($DEVMODE))
    
    If @error Then
        $B = 0
        SetError(1)
        Return $B
    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, $i_Width, 2)
        DllStructSetData($DEVMODE, 4, $i_Height, 3)
        DllStructSetData($DEVMODE, 4, $i_BitsPP, 1)
        DllStructSetData($DEVMODE, 4, $i_RefreshRate, 5)
    
        $B = DllCall("user32.dll", "int", "ChangeDisplaySettingsEx","str", $s_Display, "ptr", DllStructGetPtr($DEVMODE), "hwnd", 0, "dword", $CDS_TEST, "lparam", 0)
        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", "ChangeDisplaySettingsEx","str", $s_Display, "ptr", DllStructGetPtr($DEVMODE), "hwnd", 0, "dword", $CDS_UPDATEREGISTRY, "lparam", 0)
                DllCall("user32.dll", "int", "SendMessage", "hwnd", $HWND_BROADCAST, "int", $WM_DISPLAYCHANGE, _
                        "int", $i_BitsPP, "int", $i_Height * 2 ^ 16 + $i_Width)
                $DEVMODE = ""
                Return 1
            Case Else
                $DEVMODE = ""
                SetError(1)
                Return $B
        EndSelect
    EndIf
EndFunc;==>_ChangeScreenResEx

And here is what I have been using to test it.

#include <ChangeResolutionEx.au3>

_ChangeScreenResEx(1,1024,600,-1,-1)
_ChangeScreenResEx(2,1680,1050,-1,-1)

I am still struggling with the DetachMonitorEx.Au3 UDF but I hope to get that working soon. It seems to involve mucking with the $DEVMODE flags and then calling the ChangeDisplaySettingsEx twice, but it is not working as of now.

Bob

:)
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
Link to comment
Share on other sites

Hey guys,

I can use this au3 file to change to any resolution I've tried except for 1152x864. If I try it, I get the error that says can't change resolution - check parameters.

I can switch to this resolution via the Display properties (Winxp SP3), so not sure why it doesn't work in the script? Is there something hard-coded in the au3 file to only allow certain resolutions?

EDIT: n/m, works on another PC, so it's obviously something specific with the monitor.

Edited by WorknMan
Link to comment
Share on other sites

  • 2 weeks later...

Hey guys,

I can use this au3 file to change to any resolution I've tried except for 1152x864. If I try it, I get the error that says can't change resolution - check parameters.

I can switch to this resolution via the Display properties (Winxp SP3), so not sure why it doesn't work in the script? Is there something hard-coded in the au3 file to only allow certain resolutions?

EDIT: n/m, works on another PC, so it's obviously something specific with the monitor.

Are you working on a single monitor or on multiple monitor system?

--------------------bobchernow, Bob ChernowWhat a long strange trip it's beenUDFs: [post="635594"]Multiple Monitor Screen Resolution Change[/post]

Link to comment
Share on other sites

  • 2 months later...
  • 2 months later...
  • 1 month later...

hello everybody

how can add a condition for this script ????

I mean :

if ( width <= 800 ^ Height <= 600 ) change to 1024x768 and even if one of them ( width or height ) was <= last value also change to 1024x768

I mean I wanna the width > 800 and the height > 600

but if the resolution was bigger than 800x600 for example (1152x864) don't do any thing

thanks so much

Edited by AlienStar
Link to comment
Share on other sites

  • 1 year later...

Inspired by original thread. All credit should go to psandu.ro, I just converted his code into a UDF and modified it slightly.

Hi,

I am new to this forum and AutoIt in general. I discovered this old post and this could be interesting for me, but i can't manage to find the "ChangeResolution.au3" file to test it (it is not in the AutoIt standard library, isn't it?).

Could someone tell me how to download it?

PS. I am using the version v3.3.6.1 of AutoIt

Thanks in Advance for the answers.

Link to comment
Share on other sites

  • 2 weeks later...

PsaltyDS posted it, just copy code and save it as au3 file.

I'm really new to Scripting and AutoIt and am having a lot of trouble with this. All I want to do is change a users screen resolution. I copied PsaltyDS's code and saved it as "ChangeResolution.au3" in the include folder in AutoIt. I've tried running the following code:

#include <ChangeResolution.au3>

$iWidth = 1024

$iHeight = 768

$iBitsPP = 32

$iRefreshRate = 60

$vRes = _ChangeScreenRes($iWidth, $iHeight, $iBitsPP, $iRefreshRate)

If @error Then

MsgBox(262160, "ERROR", "Unable to change screen - check parameters")

EndIf

And all I get is the following error:

>"C:\Program Files\AutoIt3\SciTE\..\autoit3.exe" /ErrorStdOut "C:\Users\<username>\Desktop\AutoIt3\Scripts\resolution test.au3"

C:\Users\<username>\Desktop\AutoIt3\Scripts\resolution test.au3 (8) : ==> Unknown function name.:

$vRes = _ChangeScreenRes($iWidth, $iHeight, $iBitsPP, $iRefreshRate)

$vRes = ^ ERROR

>Exit code: 1 Time: 0.244

I've been through tons of posts and I'm pretty frustrated, I didn't thing changing the screen resolution would be so complicated...

Any help would be appreciated!!!

Thanks

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