I have no interest or ability in learning how to program this, but
I need a function to change screen resolution once, and then be
able to change it back again shortly thereafter. It must work in
all windows OS, XP to W8, and in all the newest screen resolutions.
I actually need to change the resolution to 1024x768 and then
shortly there after change it back to the users normal resolution.
The users normal resolution will be obtained with A_ScreenWidth
and A_ScreenHeight. I am using AHK_L v1.1+ unicode
I have seen a number of these functions on the ahk forum and
some crash my PC on the return trip, and some, like this one below,
will set it once, but will not return it back to the original resolution.
I have seen some that can set 1024x768 to 800x600 or 640x480,
but don't work if starting out with 1280x800. This needs to work
for example on W8/7 with 1366x768, and XP with 1440x900, hopefully
all the various resolutions out there.
Right now I am using a freeware command line program called qres.exe.
It seems a shame I have to go outside ahk for this though. Unless someone
with the skill level of say. jethrow, can make this work with some certainty
I will probably stick with the freeware program.
Code: Select all
ChangeDisplaySettings( cD, sW, sH, rR )
{
;Calculate offset of DEVMODE fields:
size := A_IsUnicode ? 220 : 156
smSize := A_IsUnicode ? 68 : 36
dmFields := dmSize + 4
dmBitsPerPel := A_IsUnicode ? 168 : 104
dmPelsWidth := dmBitsPerPel + 4
dmPelsHeight := dmPelsWidth + 4
dmDisplayFrequency := dmPelsHeight + 8
VarSetCapacity(dM,size,0), NumPut(size,&dM,dmSize,"UShort")
DllCall( "EnumDisplaySettings", UInt,0, UInt,-1, UInt,&dM )
NumPut(0x5c0000,dM,dmFields,"UInt")
NumPut(cD,dM,dmBitsPerPel,"UInt"), NumPut(sW,dM,dmPelsWidth,"UInt")
NumPut(sH,dM,dmPelsHeight,"UInt"), NumPut(rR,dM,dmDisplayFrequency,"UInt")
Return DllCall( "ChangeDisplaySettings", UInt,&dM, UInt,0 )
}
ps: Please post the code without the line numbers, as I have IE9/7 and it always
picks up the numbers when I copy/paste the code, if there are line numbers.