How can I change screen resolution in win10

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
woshichuanqilz72
Posts: 117
Joined: 05 Oct 2015, 21:23

How can I change screen resolution in win10

21 Nov 2015, 03:47

The below code works fine in winxp and win7

But it can't work in win10, how can I fix it?

Code: Select all

F12::  ;改变显示分辨率为1024*768   winxp,win7正常工作,求改为win10可用
w=1280 
h=1024

  VarSetCapacity(dM,156,0)
  NumPut(156,dM,36)
  NumPut(0x5c0000,dM,40)
  NumPut(w,dM,108)
  NumPut(h,dM,112)
  DllCall( "ChangeDisplaySettingsA", UInt,&dM, UInt,0 )

return
lexikos
Posts: 9583
Joined: 30 Sep 2013, 04:07
Contact:

Re: How can I change screen resolution in win10

21 Nov 2015, 04:14

You are calling the function incorrectly. Perhaps Windows 10 has more robust error checking. 0x5c0000 breaks down to the following flags:

Code: Select all

#define DM_BITSPERPEL	0x40000
#define DM_PELSWIDTH	0x80000
#define DM_PELSHEIGHT	0x100000
#define DM_DISPLAYFREQUENCY 0x400000
Basically, you are requesting that the bits per pixel and display frequency are both set to zero. Zero is not valid. You should only set the flags corresponding to the fields you actually gave proper values: width and height. In other words, replace 0x5c0000 with 0x180000.
stayawesome
Posts: 18
Joined: 25 Jan 2015, 01:15

Re: How can I change screen resolution in win10

22 Nov 2015, 23:07

I use this to quicky change between two resolution on win10
^8::
ChangeDisplaySettings(32,1366,768,60)
return

^9::
ChangeDisplaySettings(32,1280,768,60)
return

ChangeDisplaySettings( (ClrDep:=32) , (Wid:=1280) , (Hei:=1024) , (Hz:=60) )

ChangeDisplaySettings( cD, sW, sH, rR ) {
VarSetCapacity(dM,156,0), NumPut(156,2,&dM,36)
DllCall( "EnumDisplaySettings", UInt,0, UInt,-1, UInt,&dM ), NumPut(0x5c0000,dM,40)
NumPut(cD,dM,104), NumPut(sW,dM,108), NumPut(sH,dM,112), NumPut(rR,dM,120)
Return DllCall( "ChangeDisplaySettings", UInt,&dM, UInt,0 )
}
Klaus2
Posts: 6
Joined: 11 Jan 2016, 04:16

Re: How can I change screen resolution in win10

11 Jan 2016, 05:54

stayawesome wrote:I use this to quicky change between two resolution on win10
Spoiler
On my system this code doesn't have any meaningful effect as of Windows 10. The screen blinks briefly, but the settings don't change in any visible manner.

As a workaround I am currently interfacing with some Python3 code:

Code: Select all

# 2>/NUL & python %~dpf0 %* & goto :EOF 
# FILENAME: SetResolution.cmd, anywhere on PATH. 
# Set screen resolution to command line arguments.
MANUAL=\
"""

Usage: SetResolution WIDTHPIXELS HEIGHTPIXELS

Requires the win32api module, which requires PATH
to be correctly configured. If you experience 
errors saying that a DLL couldn't be found, it is
not. 

Specifically with the WinPython distribution you
need to make sure that the script is executed by
python.bat (which configures PATH) and not 
python.exe (which doesn't). 

"""

import sys
if len(sys.argv) != 3:
    print(MANUAL)
    sys.exit(1)
else:
    import win32api
    x = win32api.EnumDisplaySettings(None, 0)
    x.PelsWidth, x.PelsHeight = [ int(x) for x in sys.argv[1:] ]
    print("Trying to set resolution to {:d}x{:d}".format(
        x.PelsWidth, x.PelsHeight))
    print("Win32API-call returned {}".format(
        repr(win32api.ChangeDisplaySettings(x,0))))

garry
Posts: 3763
Joined: 22 Dec 2013, 12:50

Re: How can I change screen resolution in win10

11 Jan 2016, 08:03

another example here :
https://autohotkey.com/boards/viewtopic.php?f=5&t=12684

Code: Select all

; screenx resolutionx XPx / Windows10x
;-------- saved at Samstag, 9. Januar 2016 11:38:38 --------------
;-------- https://autohotkey.com/boards/viewtopic.php?f=5&t=12684 ---
^F12::
ChangeResolution(1280, 720)
Return

!F12::
ChangeResolution(1920, 1080)
Return

ChangeResolution(Screen_Width := 1920, Screen_Height := 1080, Color_Depth := 32)
{
	VarSetCapacity(Device_Mode,156,0)
	NumPut(156,Device_Mode,36)
	DllCall( "EnumDisplaySettingsA", UInt,0, UInt,-1, UInt,&Device_Mode )
	NumPut(0x5c0000,Device_Mode,40)
	NumPut(Color_Depth,Device_Mode,104)
	NumPut(Screen_Width,Device_Mode,108)
	NumPut(Screen_Height,Device_Mode,112)
	Return DllCall( "ChangeDisplaySettingsA", UInt,&Device_Mode, UInt,0 )
}
Return
rbuccigrossi

Re: How can I change screen resolution in win10

22 Jul 2016, 23:27

I just upgraded to Windows 10 and my old AHK script didn't work either so I encountered this forum. As it turns out, the suggested script had two errors (calling "EnumDisplaySettings" instead of "EnumDisplaySettingsA" and "ChangeDisplaySettings" instead of "ChangeDisplaySettingsA".) The following worked for me (for a SEIKI 4K monitor):

Code: Select all

#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.

^6::
  ChangeResolution(32,1280,720,60)
  return

^7::
  ChangeResolution(32,1600,900,60)
  return

^8::
  ChangeResolution(32,1920,1080,60)
  return

^9::
  ChangeResolution(32,3840,2160,30)
  return

ChangeResolution( cD, sW, sH, rR ) {
  VarSetCapacity(dM,156,0), NumPut(156,2,&dM,36)
  DllCall( "EnumDisplaySettingsA", UInt,0, UInt,-1, UInt,&dM ), 
  NumPut(0x5c0000,dM,40)
  NumPut(cD,dM,104), NumPut(sW,dM,108), NumPut(sH,dM,112), NumPut(rR,dM,120)
  Return DllCall( "ChangeDisplaySettingsA", UInt,&dM, UInt,0 )
}
lexikos
Posts: 9583
Joined: 30 Sep 2013, 04:07
Contact:

Re: How can I change screen resolution in win10

23 Jul 2016, 02:24

@rbuccigrossi: You must have also "upgraded" from an ANSI version of AutoHotkey to a Unicode version, and the code was written for ANSI. Older versions are ANSI-only, but the current installer offers a choice. Unicode is better (if you can get your older scripts working).
dudeMan

Re: How can I change screen resolution in win10

22 Nov 2017, 08:42

The script to change the resolution works fine for me, but i want to know if anyone can tell me how to include the scalling into the script. That is because when I use the script the scalling is off


Thank you for your answer !

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Lamron750, nacken012, septrinus and 228 guests