windows:获取监视器的数量,包括禁用的监视器 [英] windows: get number of monitors, including disabled ones

查看:63
本文介绍了windows:获取监视器的数量,包括禁用的监视器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

EnumDisplayMonitors 列出当前激活的所有监视器.但是,它似乎没有返回禁用的那些(即未选中将我的桌面扩展到此显示器"的那些).我如何计算包括那些残疾人在内的人数?

EnumDisplayMonitors lists all the monitors that are currently activated. However, it doesn't seem to return disabled ones (i.e. ones that have 'extend my desktop onto this monitor' unchecked). How do I get a count including those disabled ones?

推荐答案

好的,所以首先你必须创建一个设备上下文:

Ok, so first you have to create a device context:

http://msdn.microsoft.com/en-us/library/dd183490(v=VS.85).aspx 以下代码将为您提供所有监视器:

http://msdn.microsoft.com/en-us/library/dd183490(v=VS.85).aspx The following code will give you all monitors:

CreateDC(TEXT("DISPLAY"),NULL,NULL,NULL)

然后您将调用 DeviceContext 的 EnumDisplayDevices,该设备将有一个指向 DISPLAY_DEVICE 结构的指针,该结构包含有关显示设备设置的信息.http://msdn.microsoft.com/en-us/library/dd162609(v=VS.85).aspx

每个 MSDN:

要查询当前会话中的所有显示设备,请循环调用此函数,从 iDevNum 设置为 0 开始,并递增 iDevNum 直到函数失败.要选择桌面中的所有显示设备,请仅使用 DISPLAY_DEVICE 结构中具有 DISPLAY_DEVICE_ATTACHED_TO_DESKTOP 标志的显示设备.

To query all display devices in the current session, call this function in a loop, starting with iDevNum set to 0, and incrementing iDevNum until the function fails. To select all display devices in the desktop, use only the display devices that have the DISPLAY_DEVICE_ATTACHED_TO_DESKTOP flag in the DISPLAY_DEVICE structure.

要获取有关显示适配器的信息,请调用 EnumDisplayDevices,并将 lpDevice 设置为 NULL.例如,DISPLAY_DEVICE.DeviceString 包含适配器名称.

To get information on the display adapter, call EnumDisplayDevices with lpDevice set to NULL. For example, DISPLAY_DEVICE.DeviceString contains the adapter name.

要获取有关显示监视器的信息,首先调用 EnumDisplayDevices,并将 lpDevice 设置为 NULL.然后调用 EnumDisplayDevices,在第一次调用 EnumDisplayDevices 时将 lpDevice 设置为 DISPLAY_DEVICE.DeviceName,并将 iDevNum 设置为零.然后 DISPLAY_DEVICE.DeviceString 是监视器名称.

To obtain information on a display monitor, first call EnumDisplayDevices with lpDevice set to NULL. Then call EnumDisplayDevices with lpDevice set to DISPLAY_DEVICE.DeviceName from the first call to EnumDisplayDevices and with iDevNum set to zero. Then DISPLAY_DEVICE.DeviceString is the monitor name.

要查询与适配器关联的所有监视器设备,请在循环中调用 EnumDisplayDevices,其中 lpDevice 设置为适配器名称,iDevNum 设置为从 0 开始,iDevNum 设置为递增直到函数失败.请注意,DISPLAY_DEVICE.DeviceName 会随着每次调用监视器信息而更改,因此您必须保存适配器名称.当适配器没有更多监视器时,该功能将失败.

To query all monitor devices associated with an adapter, call EnumDisplayDevices in a loop with lpDevice set to the adapter name, iDevNum set to start at 0, and iDevNum set to increment until the function fails. Note that DISPLAY_DEVICE.DeviceName changes with each call for monitor information, so you must save the adapter name. The function fails when there are no more monitors for the adapter.

我不是 C++ 程序员,但是我不得不编写一些东西来显示过去,我只是想帮助我记住的一点点.我对 WINAPI 有点生疏.

I am not a C++ programmer, however I had to code some stuff for display way back in the day, and I was just trying to help with the little that I remember. I am a bit rusty on WINAPI.

这篇关于windows:获取监视器的数量,包括禁用的监视器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆