以编程方式更改屏幕分辨率

时间:2008-10-18 18:46:46

标签: windows winapi resolution multiple-monitors

有没有办法在Windows XP中以编程方式更改屏幕分辨率或启用/禁用多个显示器?例如,在两台显示器上从一台显示器的1024x768更改为1280x104?我会对win32函数最感兴趣,但是任何可以绑定到Windows快捷方式的东西就足够了。

5 个答案:

答案 0 :(得分:25)

您可以使用EnumDisplayDevices找出可用的显示内容,并使用EnumDisplaySettings获取显示器的可用分辨率列表。使用ChangeDisplaySettings设置所需的分辨率。

答案 1 :(得分:2)

是的,但它不是.NET的一部分。您将需要使用,调用或编写包装器来访问Win32 API。

参见ChangeDisplaySettings及相关功能。

Here你可以找到一个基本的例子。

答案 2 :(得分:1)

您可以使用http://www.autohotkey.com

轻松编写此脚本

这是一个用Windows + 1和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

答案 3 :(得分:0)

要更改主显示器的显示分辨率:

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)

有关提供不同分辨率选择的 Python 脚本,请参阅 https://github.com/randyramsaywack/changeResolution

答案 4 :(得分:-5)

轻松阅读给定的链接。

只需下载dll就可以了..

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);