多显示器编程--获取所有显示器的分辨率

在Windows下进行多显示器编程时,需要获取每个显示器的分辨率。通过枚举系统中的显卡和DISPLAY_DEVICE,使用EnumDisplaySettingsEx等API来获取Monitor信息。在Windows7及Intel HD4000显卡上,此方法与系统显示的编号一致,但实际编号可能与硬件和驱动有关。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

最近需要在windows下进行多显示器编程,问题是:怎么样获取所有的显示器的分辨率(比如:有三个显示器M1、M2、M3,如何分别取得它们三个的分辨率)

下面是一些网友讨论的记录:

Demo: http://download.youkuaiyun.com/detail/w_sx12553/5027326

关于如何获得显示器编号的讨论:

Windows系统从来不会给某一个显示器分配一个编号!
你所看到编号,不过是系统在配置的时候,为了让你分辨不同的显示器而显示的编号。

Windows系统中的显示器始终又隐含一个编号!

在Windows系统中,通常一块显卡可以包含多个:DISPLAY_DEVICE,每一个DISPLAY_DEVICE下面可以挂接一个Monitor。

我当时是这样做的:枚举系统中的显卡,然后枚举下面的DISPLAY_DEVICE,对于每一个DISPLAY_DEVICE,检查(可以通过EnumDisplaySettingsEx)是否挂接得有Monitor。如果有,就计数。
你所看到的编号就是这些Monitor被枚举出来的顺序。
上面的方法我是在Windows7与intel 核心显卡HD4000上测试过的。2个显示器确实与Windows系统的编号一致。

个人猜测:事实上这个枚举过程所出现的结果,与系统无关,而是与显卡硬件、驱动有关。


Here's a list of API functions related to multiple monitors:

ChangeDisplaySettingsEx: changes display settings
EnumDisplayDevices: enumerates all displays, including disabled ones
EnumDisplayMonitors: enumerates all enabled displays
EnumDisplaySettingsEx: gets display settings
GetMonitorInfo: gets information about a monitor such as the working area
MonitorFromPoint: returns the monitor containing a given point
MonitorFromRect: returns the monitor containing a given rectangle
MonitorFromWindow: returns the monitor containing a given window
API functions specific to Windows 7:

QueryDisplayConfig: returns current display settings
SetDisplayConfig: sets current display settings



参考:
http://bbs.youkuaiyun.com/topics/390683091

http://blog.youkuaiyun.com/jennyvenus/article/details/42027043

http://blog.youkuaiyun.com/freewave/article/details/2033877

http://www.kuqin.com/shuoit/20131124/336528.html

http://blog.youkuaiyun.com/morewindows/article/details/8502583

http://my.oschina.net/u/1255773/blog/177533
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值