Jump to content

Recommended Posts

Posted

I'm trying to find an autoit script that I can compile for users to click to change their screen resolution to 800 x 600. We have just started using Abacus i planner which will only display full size at 800 x 600, which means that with our laptops it's actually quite difficult to read! Whilst most users are happy to change the resolution the standard way it would be easier to have a button to press:)

 

Is it possible with autoit?

Posted
I'm trying to find an autoit script that I can compile for users to click to change their screen resolution to 800 x 600. We have just started using Abacus i planner which will only display full size at 800 x 600, which means that with our laptops it's actually quite difficult to read! Whilst most users are happy to change the resolution the standard way it would be easier to have a button to press:)

 

Is it possible with autoit?

 

I have a batch file with a .exe to achieve this if your interested?

Posted
Thanks, qres is my fallback, I was hoping to use autoit as I use that for the proxy on/off for the staff laptops so just wanted to have a consistant look.
Posted

* Set the resolution to 640x480 while running an application:

 

vidres /H640 /V480 "/Xc:\path\appname.exe"

 

when appname.exe closes, the display will switch back to its original settings.

 

* Set the resolution to 640x480 only while the specified application is the active maximized window:

 

vidres /H640 /V480 "/Xc:\path\appname.exe" /R

 

If you close appname.exe, run it non-minimized, or switch to a different window, the original resolution is restored. If you switch back to appname.exe the resolution will switch back again.

  • Thanks 1
  • 1 month later...
Posted

Does anyone know a way to get the resolution to automatically change dependant on whether an external monitor/projector is connected?

 

I know that it's not much effort to make a couple of clicks, but these are teachers...

  • 2 weeks later...
Posted

Here's how to do it using AutoIt. All you need to do is compile the script, create a shortcut to the EXE and than add the desired parameters to the end of the command-line. e.g. ChangeScreenRes.exe 1280 800 32 -1

 

#NoTrayIcon
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Compression=4
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

; Define variables
$Width  = $CmdLine[1]
$Height = $CmdLine[2]
$BitsPerPixel = $CmdLine[3]
$RefreshRate = $CmdLine[4]

; Change screen resolution
_ChangeScreenRes($Width,$Height,$BitsPerPixel,$RefreshRate)

; Alternative method if you don't want to use command-line
;_ChangeScreenRes(1280,800,32,-1)

;===============================================================================
;
; Function Name:    _ChangeScreenRes()
; Description:      Changes the current screen geometry, colour and refresh rate.
; Version:          1.0.0.1
; Parameter(s):     $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):         http://www.autoitscript.com/forum/index.php?showtopic=20121
; Author(s):        Original code - psandu.ro
;                   Modifications - PartyPooper
;
;===============================================================================
Func _ChangeScreenRes($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 $B = DllCall("user32.dll", "int", "EnumDisplaySettings", "ptr", 0, "long", 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", "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", $i_BitsPP, "int", $i_Height * 2 ^ 16 + $i_Width)
			$DEVMODE = ""
			Return 1
		Case Else
			$DEVMODE = ""
			SetError(1)
			Return $B
	EndSelect
EndIf
EndFunc ;==>_ChangeScreenRes

Posted
Here's how to do it using AutoIt. All you need to do is compile the script, create a shortcut to the EXE and than add the desired parameters to the end of the command-line. e.g. ChangeScreenRes.exe 1280 800 32 -1

 

#NoTrayIcon
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Compression=4
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

; Define variables
$Width  = $CmdLine[1]
$Height = $CmdLine[2]
$BitsPerPixel = $CmdLine[3]
$RefreshRate = $CmdLine[4]

; Change screen resolution
_ChangeScreenRes($Width,$Height,$BitsPerPixel,$RefreshRate)

; Alternative method if you don't want to use command-line
;_ChangeScreenRes(1280,800,32,-1)

;===============================================================================
;
; Function Name:    _ChangeScreenRes()
; Description:      Changes the current screen geometry, colour and refresh rate.
; Version:          1.0.0.1
; Parameter(s):     $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):         http://www.autoitscript.com/forum/index.php?showtopic=20121
; Author(s):        Original code - psandu.ro
;                   Modifications - PartyPooper
;
;===============================================================================
Func _ChangeScreenRes($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 $B = DllCall("user32.dll", "int", "EnumDisplaySettings", "ptr", 0, "long", 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", "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", $i_BitsPP, "int", $i_Height * 2 ^ 16 + $i_Width)
			$DEVMODE = ""
			Return 1
		Case Else
			$DEVMODE = ""
			SetError(1)
			Return $B
	EndSelect
EndIf
EndFunc ;==>_ChangeScreenRes

 

 

Isnt it abit of a long way round when you can do it with one line in a batch file?

Posted
The main reason I like using AutoIt is that you don't have to rely on external programs if you know how to do everything within your script. Also if you are already using AutoIt to create a script to do another task it makes sense to use AutoIt (rather than a batch file) to change the resolution too. :)
Posted
The main reason I like using AutoIt is that you don't have to rely on external programs if you know how to do everything within your script. Also if you are already using AutoIt to create a script to do another task it makes sense to use AutoIt (rather than a batch file) to change the resolution too. :)

 

Good point.

 

I would have thought you could do this in group policy by now though.

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



×
×
  • Create New...