20
votes

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 1280x104 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.

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.Jonathan Leffler
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.David L Morris
That was "I totally agree... "David L Morris
I'm looking to do this for myself -- as a convenience for when I remote into a systemjacobsee
That was exactly the reason why I was looking for this.Juan

5 Answers

30
votes

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.

3
votes

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.

0
votes

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
0
votes

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.

-10
votes

Read the given link its easy.

just download the dll the good to go..

MyTactics.blogspot.in

Screen Srn=Screen.PrimaryScreen;

int tempWidth=Srn.Bounds.Width;
int tempHeight=Srn.Bounds.Height;
Console.WriteLine("Current Screen width is {0} and height is {1}.",
                   tempWidth,
                   tempHeight);