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

发布于 2024-07-07 16:36:40 字数 146 浏览 14 评论 0原文

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

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

未蓝澄海的烟 2024-07-14 16:36:40

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

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.

虐人心 2024-07-14 16:36:40

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

请参阅 ChangeDisplaySettings 及相关函数。

在这里您可以找到一个基本示例。

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.

顾北清歌寒 2024-07-14 16:36:40

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

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

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.

末蓝 2024-07-14 16:36:40

您可以使用 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

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文