Programmatically change screen resolution?
Asked Answered
N

4

23

Is there a way to programmatically change the screen resolution or enable/disable multiple monitors in Windows XP? For example to change from 1024x768 with one monitor to 1280x1024 on two monitors? I would be most interested in a win32 function to do this but anything that can be tied to a windows shortcut would suffice.

Newel answered 18/10, 2008 at 18:46 Comment(5)
I trust you would not even think of doing that without permission from the user. If you fiddled with my screen resolution, I'd be entirely pissed off with you - and would probably not use your program a second time.Aeri
I totality agree with the previous commenter. Unless this was some sort of utility for managing powerpoint presentations, it is hard to imagine an app where this would be a useful function.Textile
That was "I totally agree... "Textile
I'm looking to do this for myself -- as a convenience for when I remote into a systemNewel
That was exactly the reason why I was looking for this.Cronk
F
34

You can use EnumDisplayDevices to figure out what displays you have available and EnumDisplaySettings to get a list of available resolutions for your displays. Use ChangeDisplaySettings to set the resolution you need.

Ferrel answered 18/10, 2008 at 19:0 Comment(1)
I found a great working implementation of these APIs using C#. Easy to create a shortcut for it. If you don't want to run a program after changing the resolution, simply remove the few lines of code that the author included to start a program. In my case, I use it to lower my 4k screen resolution down to 1920x1080 before sharing my screen on WebEx. After I'm done, I have a different shortcut to reset back to max resolution.Sarcastic
I
3

Yes, but its not part of .NET. You will need to use, invoke or write a wrapper to access the Win32 API.

See ChangeDisplaySettings and related function.

Here you can find a basic example.

Indiscriminate answered 18/10, 2008 at 18:57 Comment(1)
The question wasn't about .NET.Locally
L
0

To change the display resolution for the primary display:

import win32api
import win32con
import pywintypes

devmode = pywintypes.DEVMODEType()
devmode.PelsWidth = 1920
devmode.PelsHeight = 1080

devmode.Fields = win32con.DM_PELSWIDTH | win32con.DM_PELSHEIGHT
win32api.ChangeDisplaySettings(devmode, 0)

For a python script offering selection of different resolutions, see https://github.com/randyramsaywack/changeResolution.

Lili answered 15/6, 2021 at 5:22 Comment(0)
F
-3

You can easily script this with http://www.autohotkey.com

Here's a script for swapping between one monitor and two monitors with Windows+1 and Windows+2

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
#Warn  ; Recommended for catching common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
#1::
Send {LWin}
WinWaitActive Start menu
Send Adjust Screen Resolution
Send {enter}
WinWaitActive Screen Resolution
ControlClick ComboBox3
Send {PgDn}
Send {Up} ; Select "Show desktop only on 1"
Send {enter}
Sleep 3000 ; workaround - cannot select accept/revert window?
Send {left}
Send {enter} ; accept changes
Return
#2::
Send {LWin}
WinWaitActive Start menu
Send Adjust Screen Resolution
Send {enter}
WinWaitActive Screen Resolution
ControlClick ComboBox3
Send {PgDn}
Send {Up}
Send {Up} ; Select "Extend these displays"
Send {enter}
Sleep 3000 ; workaround - cannot select accept/revert window?
Send {left}
Send {enter} ; accept changes
Return
Fertility answered 22/3, 2012 at 18:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.