|
Determining Windows resolution at runtime |
23yrold3yrold
Member #1,134
March 2001
|
I've been trying to figure out a way to run a program so it displays on a second monitor. Works fine, by making that window a popup with the dimensions of the second monitor, an x coordinate equal to the first monitor's horizontal resolution, and a y coordinate of 0. Problem being these values need to be hardcoded and if some dingus changes the monitor's resolution, things mess up. Making notes in readme's that the resolution must be such and such is fine, but I'm trying to make these programs idiot-proof, plus I don't like making multiple builds with different hard-coded variables. Anyone know of some sort of Win32 method for getting the monitor resolutions dynamically at runtime so I can always position the window at the desktop's right edge, and at the second monitor's resolution? I may have asked this before, but it bothers me that I can't find a way to do it. Be real nice if the program was all automated and stuff ... -- |
Jakub Wasilewski
Member #3,653
June 2003
|
You can call EnumDisplayDevices repeatedly (with a device of NULL) to get to your monitors. This will yield a number of DISPLAY_DEVICE structs, you'll have to check which of them correspond to monitors. Then, you can EnumDisplaySettings with the DISPLAY_DEVICE.DeviceName and iModeNum=ENUM_CURRENT_SETTINGS to get actual information about the current resolution. This is based on a rusty and incomplete knowledge of WinAPI, but with MSDN you might be able to make something out of it . --------------------------- |
23yrold3yrold
Member #1,134
March 2001
|
You're more or less mentioning the structures and stuff that cropped up the last time I looked into this, but I was unable to translate it into actual code ... -- |
Jakub Wasilewski
Member #3,653
June 2003
|
Let's see:
On my system, it shows this: Adapter 1: \\.\DISPLAY1 resolution: 1280x960 Adapter 2: \\.\DISPLAYV1 Unable to get settings for device. Adapter 3: \\.\DISPLAYV2 Unable to get settings for device. I think that on a multi-monitor system there will be at least two DISPLAYs. I'm not sure what those V1 and V2 are, but I think it's safe to ignore any adapters for which you are not able to retrieve settings. EDIT: By the way, what is it for? --------------------------- |
23yrold3yrold
Member #1,134
March 2001
|
Well, I run it and it detects my main resolution easily enough, so I'll call it win. I can't get my Windows settings to accept a secondary; keeps seeming to disable it, so I can't test here if it works for getting that second resolution. This is still a small victory though, so I assume the code works as intended and I grant you cookies. Now to look it over and see how it works. And it's for the kids I teach at church. We're kinda media driven and my supervisor is always asking me to write a program for this and that. It needs to go to the second monitor on the computer to display up front for the kids, and I've torn out a fair share of hair getting it working in a satisfactory manner. Think I may finally have it. -- |
MiquelFire
Member #3,110
January 2003
|
Note, the second monitor may have it's right edge at 0, so it's left side is some negative value (depends on it's horizontal resolution). --- |
Jakub Wasilewski
Member #3,653
June 2003
|
Well, this is a little late, but here is a simpler and better solution, using the proper function:
I knew it was EnumDisplaySomethings, I just picked the wrong one the first time around . This way you get both coordinates for the monitor, so you always know where exactly to display the window. The callback is called repeatedly as long as there are monitors left, and as long as you return true from it. Perhaps someone from the forums with multiple monitors at hand could test it? --------------------------- |
Matthew Leverton
Supreme Loser
January 1999
|
Quote:
Monitor 1: Monitor 2: Monitor 3: Works for me. |
MiquelFire
Member #3,110
January 2003
|
Quote:
Monitor 1: Monitor 2: Works here as well. --- |
BAF
Member #2,981
December 2002
|
Quote:
Monitor 1: Works fine for one monitor. |
23yrold3yrold
Member #1,134
March 2001
|
Sounds awesome. I'll put it to good use; thanks again. -- |
|