Jump to content
  • Advertisement
Sign in to follow this  
Tiggeh

Query monitor presence

This topic is 5417 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Lo ppl :) Hoping you can help me out here. Is there any way to check if a monitor is present (ie. connected)? I was thinking of ops such as changing res, but that is very invasive. Possibly set up an OGL/DX context and performing some checks for support of a common pixel format on a specific output? The program also needs to notice if the monitor is unplugged, however as long as queries are reliable (and not system intensive), they could be performed on a regular basis. Thanks for any help :)

Share this post


Link to post
Share on other sites
Advertisement
I put together a sample program illustrating how to use the GDI display device enumeration functions to check this:

Note the EnumDisplaySettings(...) function call; when you pass ENUM_CURRENT_SETTINGS it retrieves the current state. If it returns TRUE the device is initialized, and has a graphics mode.


#include <windows.h>
#include <wingdi.h>
#include <stdio.h>

int main(int argc, char **argv)
{
DISPLAY_DEVICE dd;
int dev = 0;
dd.cb = sizeof(DISPLAY_DEVICE);
printf("Enumerating display devices:\n");
while(EnumDisplayDevices(NULL, dev, &dd, 0))
{
DEVMODE dm;
dd.cb = sizeof(DISPLAY_DEVICE);
dm.dmSize = sizeof(DEVMODE);

printf("\nDevice : %s \t {%s}\n", dd.DeviceName, dd.DeviceString);
printf("Context : %s\n", dd.DeviceID);
if (dd.StateFlags & DISPLAY_DEVICE_ATTACHED_TO_DESKTOP) printf("Part of Desktop\n");
if (dd.StateFlags & DISPLAY_DEVICE_MIRRORING_DRIVER) printf("Pseudo device for monitoring\n");
if (dd.StateFlags & DISPLAY_DEVICE_MODESPRUNED) printf("Multiple Display Modes\n");
if (dd.StateFlags & DISPLAY_DEVICE_PRIMARY_DEVICE) printf("Primary Display Adapter\n");
if (dd.StateFlags & DISPLAY_DEVICE_REMOVABLE) printf("Removable Device (?!?)\n");
if (dd.StateFlags & DISPLAY_DEVICE_VGA_COMPATIBLE) printf("VGA Compatible\n");

if (EnumDisplaySettings(dd.DeviceName, ENUM_CURRENT_SETTINGS, &dm))
{
printf("Status\n");
printf("Device : %s\n", dm.dmDeviceName);
printf("Bits per Pel: %d\n", dm.dmBitsPerPel);
printf("Pel Width : %d\n", dm.dmPelsWidth);
printf("Pel Height : %d\n", dm.dmPelsHeight);
printf("Frequency : %d\n", dm.dmDisplayFrequency);
}

dev++;
}

if (dev == 0) {
printf("\nApparently there are no devices connected...");
}
}



Here is sample output with my system:


Enumerating display devices:

Device : \\.\DISPLAY1 {3dfx Voodoo3}
Context : PCI\VEN_121A&DEV_0005&SUBSYS_0036121A&REV_01
Part of Desktop
Status
Device : 3dfxvs
Bits per Pel: 32
Pel Width : 1024
Pel Height : 768
Frequency : 75

Device : \\.\DISPLAY2 {RADEON 7500 SERIES }
Context : PCI\VEN_1002&DEV_5157&SUBSYS_0F2A1787&REV_00
Part of Desktop
Multiple Display Modes
Primary Display Adapter
Status
Device : ATI2DVAG
Bits per Pel: 32
Pel Width : 1280
Pel Height : 1024
Frequency : 75

Device : \\.\DISPLAY3 {RADEON 7500 SERIES }
Context : PCI\VEN_1002&DEV_5157&SUBSYS_0F2A1787&REV_00
Removable Device (?!?)

Device : \\.\DISPLAYV1 {NetMeeting driver}
Context :
Pseudo device for monitoring

Device : \\.\DISPLAYV2 {RDPDD Chained DD}
Context :
Pseudo device for monitoring


And again after I plugged in and configured the adapter for the second port on the RADEON card...


Enumerating display devices:

Device : \\.\DISPLAY1 {3dfx Voodoo3}
Context : PCI\VEN_121A&DEV_0005&SUBSYS_0036121A&REV_01
Part of Desktop
Status
Device : 3dfxvs
Bits per Pel: 32
Pel Width : 1024
Pel Height : 768
Frequency : 75

Device : \\.\DISPLAY2 {RADEON 7500 SERIES }
Context : PCI\VEN_1002&DEV_5157&SUBSYS_0F2A1787&REV_00
Part of Desktop
Multiple Display Modes
Primary Display Adapter
Status
Device : ATI2DVAG
Bits per Pel: 32
Pel Width : 1280
Pel Height : 1024
Frequency : 75

Device : \\.\DISPLAY3 {RADEON 7500 SERIES }
Context : PCI\VEN_1002&DEV_5157&SUBSYS_0F2A1787&REV_00
Removable Device (?!?)

Device : \\.\DISPLAYV1 {NetMeeting driver}
Context :
Pseudo device for monitoring

Device : \\.\DISPLAYV2 {RDPDD Chained DD}
Context :
Pseudo device for monitoring

Share this post


Link to post
Share on other sites
Thanks for the code :) I'm sure I'll use it in the future, but its not as responsive as I need. If I physically unplug a device while the PC is running, it still appears as initialised and ready to use if I run the program again :(

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!