Jump to content

about screen resolution change


novi
 Share

Recommended Posts

Try this!

DisplayChangeRes(1024, 768, 32, 85)

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

Link to comment
Share on other sites

  • 3 weeks later...

Try this!

CODE

DisplayChangeRes(1024, 768, 32, 85)

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

Oh, the brain pain!

I am in need of a script to change screen resolution myself. I don't want to add any executables to the target server under load if at all possible, so I would prefer to accomplish it from a compiled AutoIT script that did not call anything outside that isn't native to the Windows (2000 and 2003) load.

This script didn't look right when I read it, because it calls dll functions that are not in AutoIT. I pasted it into SciTE and it failes checks and won't compile, as expected.

Where do the DLLStructCreate(), and DllStructSetData() functions come from? Is there an #include file with these functions? Are they calls to VBScript or something outside of AutoIT?

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

Oh, the brain pain!

I am in need of a script to change screen resolution myself. I don't want to add any executables to the target server under load if at all possible, so I would prefer to accomplish it from a compiled AutoIT script that did not call anything outside that isn't native to the Windows (2000 and 2003) load.

This script didn't look right when I read it, because it calls dll functions that are not in AutoIT. I pasted it into SciTE and it failes checks and won't compile, as expected.

Where do the DLLStructCreate(), and DllStructSetData() functions come from? Is there an #include file with these functions? Are they calls to VBScript or something outside of AutoIT?

hey man!!!! :P

try

http://www.autoitscript.com/autoit3/files/...-beta-Setup.exe

and work!

:lmao:

Link to comment
Share on other sites

  • Moderators

I don't know how.

To make it a UDF or submit it?

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.

Link to comment
Share on other sites

That did it!

o:) I hereby proclaim that it shalt be known throughout this land that PSANDO.RO is an AutoIT steely-eyed missile man, and that he doth rocketh! :king:

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

  • 2 months later...

When I try to run this my script gets hung at:

Case $B = $DISP_CHANGE_SUCCESSFUL
DllCall("user32.dll", "int", "ChangeDisplaySettings", "ptr", DLLStructGetPtr ($DEVMODE), "int", $CDS_UPDATEREGISTRY
on a WinXP SP2 running v3.1.1.117 .......it does change the display settings, but it get hung at that point when it tries to do the DllCall and so the script never finishes. Does anyone know what would cause this, or a way inwhich I could set a timeout within the script so that it automatically quits after something like five seconds.

One other thing does anyone if there is a beta for v3.1.1.117 AutoItX..., I was thinking about rewriting this UDF in AutoItX, but the version I have v3.1 from Aug 2005 does included support for DllStructSetData, DLLStructCreate, etc

Link to comment
Share on other sites

One other thing does anyone if there is a beta for v3.1.1.117 AutoItX..., I was thinking about rewriting this UDF in AutoItX, but the version I have v3.1 from Aug 2005 does included support for DllStructSetData, DLLStructCreate, etc

Uhh, what do you intend to do? :think: Take a look at this and rethink :(

Link to comment
Share on other sites

That's simple stuff, I'm trying to some advanced things that vbscript can't natively do like Api Calls.

Also I forgot to mention that I am running this as an regular user account.......which may be part of the problem....

But the way I look at it I probably could comment out that part of the code, since the display settings are changed anyways. From what I can tell that part of the code just tells you if the change was successful or not and wether or not you have to reboot, and since the code:

$B = DllCall("user32.dll", "int", "ChangeDisplaySettings", "ptr", DLLStructGetPtr ($DEVMODE), "int", $CDS_TEST)
is working
Link to comment
Share on other sites

  • 3 years later...

; Here's how I did it:

$res = "1600 by 1024 pixels"

run("control desk.cpl")
winwait("Display Properties")

for $i = 1 to 4
  controlcommand("Display Properties", "", "SysTabControl321", "TabRight")
next

winwait("Display Properties", "Settings")

$controltext = controlgettext("Display Properties", "Settings", "Static8")
while $controltext <> $res
  controlsend("Display Properties", "", "msctls_trackbar321", "{RIGHT}")
  $lastcontroltext = $controltext
  $controltext = controlgettext("Display Properties", "Settings", "Static8")
  if $lastcontroltext = $controltext then exitloop
wend

while $controltext <> $res ; try moving left
  controlsend("Display Properties", "", "msctls_trackbar321", "{LEFT}")
  $lastcontroltext = $controltext
  $controltext = controlgettext("Display Properties", "Settings", "Static8")
  if $lastcontroltext = $controltext then exitloop
wend


if $controltext <> $res then
;  msgbox(4096, "bad", "bad", 5)
  exit(1)
else
;  msgbox(4096, "good", "good", 5)
endif

controlclick("Display Properties", "", "OK")

winwait("Monitor Settings", "")
controlclick("Monitor Settings", "", "&Yes")

Edited by tamahome
Link to comment
Share on other sites

  • 3 months 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

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