MrYonG Posted March 7, 2012 Share Posted March 7, 2012 I was wonding if some one could help me out with a code that will: 1. Save the current Screen Resolution + refresh rate. 2. Change to 1024x768 and a refresh rate of 75 3. Run a part of my Autoit script. 4. revert back to the saved screen resolution + refresh rate. I have only found scripts that will change the screen resolution, but, which is saddly only a part of what i need. thank you in advance !! MrYonG Link to comment Share on other sites More sharing options...
DW1 Posted March 7, 2012 Share Posted March 7, 2012 Hi MrYonG,Welcome to the forums. should help get you on your way.Note: don't know the original author of the code... AutoIt3 Online Help Link to comment Share on other sites More sharing options...
MrYonG Posted March 8, 2012 Author Share Posted March 8, 2012 (edited) @danwilli, thnx for the welcome and reply . I already have the script to change desktop res + frequency. It is step 1 and 4 i am mainly having problems with. Is their a way of detecting the current display resolution and have autoit save it so that i can revert back to it at a later point in the script. The reason for this is i am using send key commands which fail if the screen resolution is different then what i use to write the script ( 1024x768 at the moment). I can think of 1 way around it ...but that would mean a massive script: if screen resolution is 800x600 then run the script for 800x600 (so it would go from 800x600 > 1024x768 > 800x600) and do this for every screen resolution ...as you can imagine a horrible mess and massive size . help much appreciated the code i have so far:saveCHANGErunBACK.au3 Edited March 8, 2012 by MrYonG Link to comment Share on other sites More sharing options...
saywell Posted March 8, 2012 Share Posted March 8, 2012 (edited) Is there a way of detecting the current display resolution and have autoit save it so that i can revert back to it at a later point in the script You could use these macros:@DesktopHeight Height of the desktop screen in pixels. (vertical resolution) @DesktopWidth Width of the desktop screen in pixels. (horizontal resolution) @DesktopDepth Depth of the desktop screen in bits per pixel. @DesktopRefresh Refresh rate of the desktop screen in hertz. and save the values in an ini file.IniDelete Deletes a value from a standard format .ini file. IniRead Reads a value from a standard format .ini file. iniReadSection Reads all key/value pairs from a section in a standard format .ini file.IniReadSectionNames Reads all sections in a standard format .ini file.IniRenameSection Renames a section in a standard format .ini file. IniWrite Writes a value to a standard format .ini file. IniWriteSection Writes a section to a standard format .ini file. William Edited March 8, 2012 by saywell MrYonG 1 Link to comment Share on other sites More sharing options...
MrYonG Posted March 8, 2012 Author Share Posted March 8, 2012 Thank you saywell !!this indeed saves the information before anything is changed !! tested and confirmed !the code:IniWrite("RESsave.ini","Height","",@DesktopHeight)IniWrite("RESsave.ini","Width","",@DesktopWidth)IniWrite("RESsave.ini","Depth","",@DesktopDepth)IniWrite("RESsave.ini","Refresh","",@DesktopRefresh)and i guess i just change Iniwrite with IniRead to get the info out of the inifile...now i just have to play around with how to get it into the script from their (yes im new to autoit )thanx for the help and i hope i dont need to waste your time any more with the last bit i mentioned .peace and love all !! Link to comment Share on other sites More sharing options...
MrYonG Posted March 8, 2012 Author Share Posted March 8, 2012 (edited) ummm ok so saving resolutions etc in the .ini works perfect but when i want to revert back to the resolution i had the script...nothing why does this not work?? ; Define screen resolution $Width = IniRead("RESsave.ini", "Width","",@DesktopWidth) $Height = IniRead("RESsave.ini", "Height","",@DesktopHeight) $BitsPerPixel = IniRead("RESsave.ini", "Depth","",@DesktopDepth) $RefreshRate = IniRead("RESsave.ini", "Refresh","",@DesktopRefresh) ; Define and set resolution _ChangeScreenRes($Width, $Height, $BitsPerPixel, $RefreshRate) the script continues but this is the part that is not working i dont get an error or anything, it simple runs without changing the screen resolution im confused Edited March 8, 2012 by MrYonG Link to comment Share on other sites More sharing options...
UEZ Posted March 8, 2012 Share Posted March 8, 2012 Have a look here: Might be helpful for you. Br, UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
MrYonG Posted March 8, 2012 Author Share Posted March 8, 2012 (edited) I fixed my problem but my script wont run now. this is the error im getting: C:Documents and SettingsMrYonGDesktopTEST.au3 (86) : ==> Duplicate function name.: Func _ChangeScreenRes($i_Width = @DesktopWidth, $i_Height = @DesktopHeight, $i_BitsPP = @DesktopDepth, $i_RefreshRate = @DesktopRefresh) expandcollapse popup; Save screen resolution IniWrite("RESsave.ini","Width","Default",@DesktopWidth) IniWrite("RESsave.ini","Height","Default",@DesktopHeight) IniWrite("RESsave.ini","Depth","Default",@DesktopDepth) IniWrite("RESsave.ini","Refresh","Default",@DesktopRefresh) ; Define screen resolution $Width = 1024 $Height = 768 $BitsPerPixel = 32 $RefreshRate = 85 ; Define and set resolution _ChangeScreenRes(1024,768,32,85) 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 ;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: ;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: ;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: ;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: sleep (3500) ;THE SLEEP FUNCTION IS SIMULATING MY SCRIPT ;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: ;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: ;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: ;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: $DRW = IniRead("RESsave.ini","Width","Default",@DesktopWidth) $DRH = IniRead("RESsave.ini","Height","Default",@DesktopHeight) $DD = IniRead("RESsave.ini","Depth","Default",@DesktopDepth) $DR = IniRead("RESsave.ini","Refresh","Default",@DesktopRefresh) ; Define and set resolution _ChangeScreenRes($DRW,$DRH,$DD,$DR) 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 Edited March 8, 2012 by MrYonG Link to comment Share on other sites More sharing options...
DW1 Posted March 8, 2012 Share Posted March 8, 2012 The error spells it out pretty good you are defining the function twice. You only need to define the function once. NOTE: I am not sure that my verbage is correct with "Defining", but the point is, only put it in there once. Most of us put our functions at the end of our scripts. MrYonG 1 AutoIt3 Online Help Link to comment Share on other sites More sharing options...
memphist0 Posted March 8, 2012 Share Posted March 8, 2012 I've tried the examples you guys have shown and it works great under XP but it doesn't seem to do anything in Win 7 32 or 64. Any suggestions? Link to comment Share on other sites More sharing options...
MrYonG Posted March 8, 2012 Author Share Posted March 8, 2012 (edited) haha, makes sense danwilli ... *is happy red faces are not visible via forums*ok so when i remove the function on the part where i want to change back to the resolution stored in the .ini file the error is gone ! HATS OFF to danwilli + saywell ... you saved me MANY grey hairs ... hahato anyone interested: Attached is the working script working.au3 Edited March 8, 2012 by MrYonG Link to comment Share on other sites More sharing options...
MrYonG Posted March 8, 2012 Author Share Posted March 8, 2012 (edited) I've tried the examples you guys have shown and it works great under XP but it doesn't seem to do anything in Win 7 32 or 64. Any suggestions?I wish i could help, i just started with auto it 4days ago...but i hope in time i will be able to repay the help i have received.but: try running as administrator ... or try searching for "run as admin" im sure their is a script you can add to the start... Edited March 8, 2012 by MrYonG Link to comment Share on other sites More sharing options...
memphist0 Posted March 8, 2012 Share Posted March 8, 2012 (edited) I have other autoit scripts I'm running under 7 so I'm used to the right clicking for runas. I tied what you added and regedit is launching so I assume the rest is trying to execute. Forgot to mention, Ia m also trying the HRC script mentioned and that one works so I'm trying to find out what the difference is. Which OS are you running this under? Edited March 8, 2012 by memphist0 Link to comment Share on other sites More sharing options...
MrYonG Posted March 8, 2012 Author Share Posted March 8, 2012 (edited) winXP pro ... running with out an issue. download my last .au3 file as it might have something to do with the copy paste... Edited March 8, 2012 by MrYonG Link to comment Share on other sites More sharing options...
MrYonG Posted March 8, 2012 Author Share Posted March 8, 2012 (edited) memphist0, i was just about to go to bed as its 4am here...but needed to post this.if your screen resolution is already is 1024x768 ... nothing will change.edit this part of the script to get your desired resolution during the running of the script; Define screen resolution $Width = 1024 $Height = 768 $BitsPerPixel = 32 $RefreshRate = 85 ; Define and set resolution _ChangeScreenRes(1024,768,32,85)and the rest will change your resolution back to what is was before your ran it. Edited March 8, 2012 by MrYonG Link to comment Share on other sites More sharing options...
Jolly Posted December 7, 2012 Share Posted December 7, 2012 I am new at this I mean at autoo it i just need your help i want to change my resolution Is this right? I mean check this I wanna change resolution of my script at starting and when my work is done I wanna change it back to normal so it is here can you tell me how can i do this . IniWrite("RESsave.ini","Width","Default",@DesktopWidth) IniWrite("RESsave.ini","Height","Default",@DesktopHeight) IniWrite("RESsave.ini","Depth","Default",@DesktopDepth) IniWrite("RESsave.ini","Refresh","Default",@DesktopRefresh) $Width = 1280 $Height = 1024 $BitsPerPixel = 32 $RefreshRate = 75 _ChangeScreenRes (1280,1024,32,75) HotKeySet("{Esc}", "Terminate") Sleep(1000) MouseMove (214,1002) Sleep(500) mouseclick ("left") Sleep(500) MouseClickDrag ("Left", 836, 472, 518, 520) Sleep(7000) MouseClickDrag ("Left", 967, 671, 703, 673) Func Terminate() Exit 0 EndFunc $DRW = IniRead("RESsave.ini","Width","Default",@DesktopWidth) $DRH = IniRead("RESsave.ini","Height","Default",@DesktopHeight) $DD = IniRead("RESsave.ini","Depth","Default",@DesktopDepth) $DR = IniRead("RESsave.ini","Refresh","Default",@DesktopRefresh) _ChangeScreenRes($DRW,$DRH,$DD,$DR) there is my script in b/w them so if u can help me by editing it and posting here only . here is a little screenshot of it http://prntscr.com/ljjl8 where you can see my problem. Link to comment Share on other sites More sharing options...
BrewManNH Posted December 7, 2012 Share Posted December 7, 2012 Seems pretty obvious what the problem is, you have no function called _ChangeScreenRes. You're either missing an #include, or you miscopied the script from wherever you might have gotten it. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
olo Posted April 30, 2013 Share Posted April 30, 2013 How do you get the script to revert back? Link to comment Share on other sites More sharing options...
Ponto0n Posted December 7, 2015 Share Posted December 7, 2015 (edited) i know this is an old thread, but this script does exactly what I need it to do. almost. it seems to work fine for certain resolutions and not work at all for others. my laptops default resolution is 1366x768. the script will change the resolution to something else and run my script, but it won't change it back to 1366x768. it will however change it if I change my starting resolution is 1024x768 and the script changes it to 800x600 and back to 1024x768. any reason it wouldn't go back to the 1366x768 resolution which is my recommended resolution but will do others? Edited December 7, 2015 by Ponto0n Link to comment Share on other sites More sharing options...
zalomalo Posted December 12, 2015 Share Posted December 12, 2015 (edited) I think is a refresh rate issue, may be you can 75Hz at 800x600 but not un your native resolution (present LCD monitors(NO-CRT) uses 59/60Hz);try with every RefreshRate = 60 (Hz). I have customized the function for myself, chers. expandcollapse popup; #FUNCTION# ==================================================================================================================== ; Nombre: _SetScreenResVidMode ; Author: MrYonG ; Adapted: Zalomalo 0+4 ; Cambia el Modo de Video (resolucion de la pantalla primaria). ; ------------------------------------------------------------------------------------------------------------------------------- Func _SetScreenResVidMode($DeskWidth=@DesktopWidth,$DeskHeight=@DesktopHeight,$DeskDepth=@DesktopDepth,$DeskRefresh=@DesktopRefresh) If StringIsSpace($DeskWidth) Or ($DeskWidth = -1) Then $DeskWidth=@DesktopWidth ; default Nulls to currents settings If StringIsSpace($DeskHeight) Or ($DeskHeight = -1) Then $DeskHeight=@DesktopHeight If StringIsSpace($DeskDepth) Or ($DeskDepth = -1) Then $DeskDepth=@DesktopDepth If StringIsSpace($DeskRefresh) Or ($DeskRefresh = -1) Then $DeskRefresh=@DesktopRefresh If $DeskWidth = @DesktopWidth And $DeskHeight = @DesktopHeight And $DeskDepth = @DesktopDepth And $DeskRefresh = @DesktopRefresh Then Return(1) Local $DeviceMODE=DllStructCreate('byte[32];int[10];byte[32];int[6]') Local $erRes=DllCall('User32.dll','int','EnumDisplaySettings','ptr',0,'long',0,'ptr',DllStructGetPtr($DeviceMODE)) If @error Then $DeviceMODE=Null Return(SetError(1,0,0)) EndIf If $erRes[0] <> 0 Then ; DM_PELSWIDTH, DM_PELSHEIGHT, DM_BITSPERPEL, DM_DISPLAYFREQUENCY DllStructSetData($DeviceMODE,2, BitOR(0x00080000, 0x00100000, 0x00040000, 0x00400000) ,5) DllStructSetData($DeviceMODE,4,$DeskWidth,2) DllStructSetData($DeviceMODE,4,$DeskHeight,3) DllStructSetData($DeviceMODE,4,$DeskDepth,1) DllStructSetData($DeviceMODE,4,$DeskRefresh,5) ; 0x00000002=CDS_TEST $erRes=DllCall('User32.dll','int','ChangeDisplaySettings','ptr',DllStructGetPtr($DeviceMODE),'int',0x00000002) If @error Then $erRes[0]=-1 If $erRes[0] = 1 Then ; 1=DISP_CHANGE_RESTART $DeviceMODE=Null Return(2) ElseIf $erRes[0] = 0 Then ; 0=DISP_CHANGE_SUCCESSFUL ; 0x00000001=CDS_UPDATEREGISTRY DllCall('User32.dll','int','ChangeDisplaySettings','ptr',DllStructGetPtr($DeviceMODE),'int',0x00000001) DllCall('User32.dll','int','SendMessage','hwnd',0xFFFF,'int',0x007E,'int',$DeskDepth,'int',$DeskHeight*2^16+$DeskWidth) $DeviceMODE=Null ; 0xFFFF=HWND_BROADCAST, 0x007E=WM_DISPLAYCHANGE Return(1) EndIf EndIf $DeviceMODE=Null Return(SetError(1,0,$erRes)) EndFunc ;==>_SetScreenResVidMode Edited December 12, 2015 by zalomalo My english shucks, i know it. 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