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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/215412/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 05:34:51  来源:igfitidea点击:

Programmatically change screen resolution?

windowswinapiresolutionmultiple-monitors

提问by jacobsee

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.

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

回答by Ferruccio

You can use EnumDisplayDevicesto figure out what displays you have available and EnumDisplaySettingsto get a list of available resolutions for your displays. Use ChangeDisplaySettingsto set the resolution you need.

您可以使用EnumDisplayDevices来确定您可以使用哪些显示器,并使用EnumDisplaySettings来获取您的显示器的可用分辨率列表。使用ChangeDisplaySettings设置您需要的分辨率。

回答by CMS

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

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

See ChangeDisplaySettingsand related function.

请参阅ChangeDisplaySettings和相关功能。

Hereyou can find a basic example.

在这里你可以找到一个基本的例子。

回答by a7drew

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

您可以使用http://www.autohotkey.com轻松编写脚本

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

这是使用 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

回答by Deepak Sharma

Read the given link its easy.

阅读给定的链接很容易。

just download the dll the good to go..

只需下载 dll 就好了..

MyTactics.blogspot.in

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