rasim Posted April 21, 2008 Share Posted April 21, 2008 Hi all!I made this script because this script don`t work for me. I tested below script on several computers and this work fine. But i want that you tested this script. Waiting for your comments. expandcollapse popup_ScreenSetting(1024, 768, 32, 100) ;==================================================================================== ; ;Function Name: _ScreenSetting() ;Description: Changes the screen resolution, color dept and refresh rate ;Version: 1.0 ;Parameters: $iWidth - Width of the desktop screen in pixels. (horizontal resolution) ; $iHeight - Height of the desktop screen in pixels. (vertical resolution) ; $iDepth - Depth of the desktop screen in bits per pixel. ; $iRefresh - Refresh rate of the desktop screen in hertz. ;Return Value(s): On Success - Screen is adjusted ; On failure - Message with error description ;Requirement(s): Tested on AutoIt 3.2.10.0 ;Autor(s): R.Gilman (a.k.a rasim); special thanks to amel27 ; ;==================================================================================== Func _ScreenSetting($iWidth = @DesktopWidth, $iHeight = @DesktopHeight, $iDepth = @DesktopDepth, $iRefresh = @DesktopRefresh) Local Const $DISP_CHANGE_SUCCESSFUL = 0 Local Const $DISP_CHANGE_RESTART = 1 Local Const $DISP_CHANGE_FAILED = -1 Local Const $DISP_CHANGE_BADMODE = -2 Local Const $DISP_CHANGE_NOTUPDATED = -3 Local Const $DISP_CHANGE_BADFLAGS = -4 Local Const $DISP_CHANGE_BADPARAM = -5 Local Const $CDS_TEST = 0x4 Local Const $CDS_UPDATEREGISTRY = 0x1 Local Const $DM_PELSWIDTH = 0x80000 Local Const $DM_PELSHEIGHT = 0x100000 Local Const $DM_BITSPERPEL = 0x40000 Local Const $DM_DISPLAYFREQUENCY = 0x400000 Local Const $ENUM_CURRENT_SETTINGS = -1 Local Const $WM_DISPLAYCHANGE = 0x007E Local Const $HWND_BROADCAST = 0xFFFF Local Const $SPI_SETNONCLIENTMETRICS = 0x2A Local $DEVMODE, $DllRet $DEVMODE = DllStructCreate("char dmDeviceName[32];ushort dmSpecVersion;ushort dmDriverVersion;short dmSize;" & _ "ushort dmDriverExtra;dword dmFields;short dmOrientation;short dmPaperSize;short dmPaperLength;" & _ "short dmPaperWidth;short dmScale;short dmCopies;short dmDefaultSource;short dmPrintQuality;" & _ "short dmColor;short dmDuplex;short dmYResolution;short dmTTOption;short dmCollate;" & _ "byte dmFormName[32];dword dmBitsPerPel;int dmPelsWidth;dword dmPelsHeight;" & _ "dword dmDisplayFlags;dword dmDisplayFrequency") $DllRet = DllCall("user32.dll", "int", "EnumDisplaySettings", "ptr", 0, "dword", $ENUM_CURRENT_SETTINGS, _ "ptr", DllStructGetPtr($DEVMODE)) $DllRet = $DllRet[0] If $DllRet = 0 Then MsgBox(16, "Error", "Unable to get graphic mode") Return False EndIf $VGA_MAP_KEY = RegRead("HKLM\HARDWARE\DEVICEMAP\VIDEO", "\Device\Video0") $VGA_KEY = StringReplace($VGA_MAP_KEY, "\Registry\Machine", "HKLM") RegWrite($VGA_KEY, "PruningMode", "REG_DWORD", 0) DllStructSetData($DEVMODE, "dmSize", DllStructGetSize($DEVMODE)) DllStructSetData($DEVMODE, "dmPelsWidth", $iWidth) DllStructSetData($DEVMODE, "dmPelsHeight", $iHeight) DllStructSetData($DEVMODE, "dmBitsPerPel", $iDepth) DllStructSetData($DEVMODE, "dmDisplayFrequency", $iRefresh) DllStructSetData($DEVMODE, "dmFields", BitOR($DM_PELSWIDTH, $DM_PELSHEIGHT, $DM_BITSPERPEL, $DM_DISPLAYFREQUENCY)) $DllRet = DllCall("user32.dll", "int", "ChangeDisplaySettings", "ptr", DllStructGetPtr($DEVMODE), "int", $CDS_TEST) $DllRet = $DllRet[0] If $DllRet <> $DISP_CHANGE_SUCCESSFUL Then Switch $DllRet Case $DISP_CHANGE_RESTART MsgBox(48, "Warning", "Restart your computer for change display settings") Case $DISP_CHANGE_FAILED MsgBox(16, "Error", "The video driver not set a new mode") Return False Case $DISP_CHANGE_BADMODE MsgBox(16, "Error", "Video mode not supported") Return False Case $DISP_CHANGE_NOTUPDATED MsgBox(16, "Error", "Unable to write in registry") Return False Case $DISP_CHANGE_BADFLAGS MsgBox(16, "Error", "Bad flags") Return False Case $DISP_CHANGE_BADPARAM MsgBox(16, "Error", "Bad parameters") Return False EndSwitch EndIf $DllRet = DllCall("user32.dll", "int", "ChangeDisplaySettings", "ptr", DllStructGetPtr($DEVMODE), "int", $CDS_UPDATEREGISTRY) $DllRet = $DllRet[0] DllCall("user32.dll", "int", "SendMessage", "hwnd", $HWND_BROADCAST, "int", $WM_DISPLAYCHANGE, _ "int", $SPI_SETNONCLIENTMETRICS, "int", 0) RegWrite($VGA_KEY, "PruningMode", "REG_DWORD", 1) $DEVMODE = "" $DllRet = "" EndFunc dandz 1 Link to comment Share on other sites More sharing options...
paulpmeier Posted April 28, 2008 Share Posted April 28, 2008 Hi rasim! I have tested your script in a VMware Workstation virtual machine (Windows XP Pro). Yes, it works fine. Paul Link to comment Share on other sites More sharing options...
Info Posted April 28, 2008 Share Posted April 28, 2008 FREAKING NICE! Link to comment Share on other sites More sharing options...
rasim Posted May 7, 2008 Author Share Posted May 7, 2008 Wow! I forgot about this topic! Guys! Thanks for your helps in testing work! Link to comment Share on other sites More sharing options...
YOUF Posted May 7, 2008 Share Posted May 7, 2008 thank you! Link to comment Share on other sites More sharing options...
kjcdude Posted September 11, 2008 Share Posted September 11, 2008 I've tried the other script and this one and still can't get it to work correctly. It errors out with "Video mode not supported" _ScreenSetting(1680, 1050, 32, 75) Link to comment Share on other sites More sharing options...
MaviATES Posted September 21, 2008 Share Posted September 21, 2008 Your orginal script work for 1024*768 but when I change it 1280*720 or other it gives an error. It errors out with "Video mode not supported" _ScreenSetting(1024, 768, 32, 100) Link to comment Share on other sites More sharing options...
TehWhale Posted September 21, 2008 Share Posted September 21, 2008 Maybe that's because your monitor/computer/video card cannot support that! Link to comment Share on other sites More sharing options...
Jolled Posted September 27, 2008 Share Posted September 27, 2008 Wow! I love it! But it gets weird when you change to wrong settings, and you need to restart the computer...(or is it only me?) Link to comment Share on other sites More sharing options...
Kip Posted September 27, 2008 Share Posted September 27, 2008 But it gets weird when you change to wrong settingsThat's because it are wrong settings. MailSpons: Fake SMTP server for safe email testing Dutch postcode & address API. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now