<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>Determining Windows  resolution at runtime</title>
		<link>http://www.allegro.cc/forums/view/591426</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Sat, 19 May 2007 04:10:55 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I&#39;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&#39;s horizontal resolution, and a y coordinate of 0. Problem being these values need to be hardcoded and if some dingus changes the monitor&#39;s resolution, things mess up.</p><p>Making notes in readme&#39;s that the resolution must be such and such is fine, but I&#39;m trying to make these programs idiot-proof, plus I don&#39;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&#39;s right edge, and at the second monitor&#39;s resolution?</p><p>I may have asked this before, but it bothers me that I can&#39;t find a way to do it. <img src="http://www.allegro.cc/forums/smileys/tongue.gif" alt=":P" /> Be real nice if the program was all automated and stuff ...
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (23yrold3yrold)</author>
		<pubDate>Thu, 17 May 2007 08:32:17 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>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&#39;ll have to check which of them correspond to monitors.</p><p>Then, you can EnumDisplaySettings with the DISPLAY_DEVICE.DeviceName and iModeNum=ENUM_CURRENT_SETTINGS to get actual information about the current resolution.</p><p>This is based on a rusty and incomplete knowledge of WinAPI, but with MSDN you might be able to make something out of it <img src="http://www.allegro.cc/forums/smileys/wink.gif" alt=";)" />.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Jakub Wasilewski)</author>
		<pubDate>Thu, 17 May 2007 14:38:23 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>You&#39;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 ...
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (23yrold3yrold)</author>
		<pubDate>Thu, 17 May 2007 16:34:48 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Let&#39;s see:</p><div class="source-code"><div class="toolbar"></div><div class="inner"><table width="100%"><tbody><tr><td class="number">1</td><td><span class="p">#include &lt;windows.h&gt;</span></td></tr><tr><td class="number">2</td><td><span class="p">#include &lt;iostream&gt;</span></td></tr><tr><td class="number">3</td><td>&#160;</td></tr><tr><td class="number">4</td><td><span class="k1">using</span> <span class="k1">namespace</span> std<span class="k2">;</span></td></tr><tr><td class="number">5</td><td>&#160;</td></tr><tr><td class="number">6</td><td><span class="k1">int</span> main<span class="k2">(</span><span class="k2">)</span></td></tr><tr><td class="number">7</td><td><span class="k2">{</span></td></tr><tr><td class="number">8</td><td>  DISPLAY_DEVICE adapter<span class="k2">;</span></td></tr><tr><td class="number">9</td><td>  adapter.cb <span class="k3">=</span> <span class="k1">sizeof</span><span class="k2">(</span>DISPLAY_DEVICE<span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">10</td><td>  </td></tr><tr><td class="number">11</td><td>  <span class="k1">int</span> i <span class="k3">=</span> <span class="n">0</span><span class="k2">;</span></td></tr><tr><td class="number">12</td><td>    </td></tr><tr><td class="number">13</td><td>  <span class="k1">while</span> <span class="k2">(</span>EnumDisplayDevices<span class="k2">(</span>NULL, i<span class="k3">+</span><span class="k3">+</span>, <span class="k3">&amp;</span>adapter, <span class="n">0</span><span class="k2">)</span><span class="k2">)</span></td></tr><tr><td class="number">14</td><td>  <span class="k2">{</span></td></tr><tr><td class="number">15</td><td>    DEVMODE mode<span class="k2">;</span></td></tr><tr><td class="number">16</td><td>    mode.dmSize <span class="k3">=</span> <span class="k1">sizeof</span><span class="k2">(</span>DEVMODE<span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">17</td><td>    mode.dmDriverExtra <span class="k3">=</span> <span class="n">0</span><span class="k2">;</span></td></tr><tr><td class="number">18</td><td>    </td></tr><tr><td class="number">19</td><td>    cout <span class="k3">&lt;</span><span class="k3">&lt;</span> <span class="s">"Adapter "</span> <span class="k3">&lt;</span><span class="k3">&lt;</span> i <span class="k3">&lt;</span><span class="k3">&lt;</span> <span class="s">": "</span> <span class="k3">&lt;</span><span class="k3">&lt;</span> adapter.DeviceName <span class="k3">&lt;</span><span class="k3">&lt;</span> endl<span class="k2">;</span></td></tr><tr><td class="number">20</td><td>    <span class="k1">if</span> <span class="k2">(</span>EnumDisplaySettings<span class="k2">(</span>adapter.DeviceName, ENUM_CURRENT_SETTINGS, <span class="k3">&amp;</span>mode<span class="k2">)</span><span class="k2">)</span></td></tr><tr><td class="number">21</td><td>      cout <span class="k3">&lt;</span><span class="k3">&lt;</span> <span class="s">"\tresolution: "</span> <span class="k3">&lt;</span><span class="k3">&lt;</span> mode.dmPelsWidth <span class="k3">&lt;</span><span class="k3">&lt;</span> <span class="s">"x"</span> <span class="k3">&lt;</span><span class="k3">&lt;</span> mode.dmPelsHeight <span class="k3">&lt;</span><span class="k3">&lt;</span> endl<span class="k2">;</span></td></tr><tr><td class="number">22</td><td>    <span class="k1">else</span></td></tr><tr><td class="number">23</td><td>      cout <span class="k3">&lt;</span><span class="k3">&lt;</span> <span class="s">"Unable to get settings for device."</span> <span class="k3">&lt;</span><span class="k3">&lt;</span> endl<span class="k2">;</span></td></tr><tr><td class="number">24</td><td>  <span class="k2">}</span></td></tr><tr><td class="number">25</td><td>  </td></tr><tr><td class="number">26</td><td>  <span class="k1">return</span> <span class="n">0</span><span class="k2">;</span></td></tr><tr><td class="number">27</td><td><span class="k2">}</span></td></tr></tbody></table></div></div><p>

On my system, it shows this:
</p><pre>
Adapter 1: \\.\DISPLAY1
        resolution: 1280x960
Adapter 2: \\.\DISPLAYV1
Unable to get settings for device.
Adapter 3: \\.\DISPLAYV2
Unable to get settings for device.
</pre><p>

I think that on a multi-monitor system there will be at least two DISPLAYs. I&#39;m not sure what those V1 and V2 are, but I think it&#39;s safe to ignore any adapters for which you are not able to retrieve settings.</p><p>EDIT: By the way, what is it for?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Jakub Wasilewski)</author>
		<pubDate>Thu, 17 May 2007 17:05:18 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Well, I run it and it detects my main resolution easily enough, so I&#39;ll call it win. I can&#39;t get my Windows settings to accept a secondary; keeps seeming to disable it, so I can&#39;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. <img src="http://www.allegro.cc/forums/smileys/grin.gif" alt=";D" /></p><p>And it&#39;s for the kids I teach at church. We&#39;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&#39;ve torn out a fair share of hair getting it working in a satisfactory manner. Think I may finally have it.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (23yrold3yrold)</author>
		<pubDate>Fri, 18 May 2007 05:51:50 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Note, the second monitor may have it&#39;s right edge at 0, so it&#39;s left side is some negative value (depends on it&#39;s horizontal resolution).
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (MiquelFire)</author>
		<pubDate>Fri, 18 May 2007 06:05:10 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Well, this is a little late, but here is a simpler and better solution, using the proper function:</p><div class="source-code"><div class="toolbar"></div><div class="inner"><table width="100%"><tbody><tr><td class="number">1</td><td><span class="p">#include &lt;windows.h&gt;</span></td></tr><tr><td class="number">2</td><td><span class="p">#include &lt;iostream&gt;</span></td></tr><tr><td class="number">3</td><td>&#160;</td></tr><tr><td class="number">4</td><td><span class="k1">using</span> <span class="k1">namespace</span> std<span class="k2">;</span></td></tr><tr><td class="number">5</td><td>&#160;</td></tr><tr><td class="number">6</td><td>BOOL callback<span class="k2">(</span>HMONITOR hMonitor, HDC hdc, LPRECT <a href="http://www.allegro.cc/manual/rect" target="_blank"><span class="a">rect</span></a>, LPARAM data<span class="k2">)</span></td></tr><tr><td class="number">7</td><td><span class="k2">{</span></td></tr><tr><td class="number">8</td><td>  <span class="k1">static</span> <span class="k1">int</span> no <span class="k3">=</span> <span class="n">1</span><span class="k2">;</span></td></tr><tr><td class="number">9</td><td>  </td></tr><tr><td class="number">10</td><td>  cout <span class="k3">&lt;</span><span class="k3">&lt;</span> <span class="s">"Monitor "</span> <span class="k3">&lt;</span><span class="k3">&lt;</span> no <span class="k3">&lt;</span><span class="k3">&lt;</span> <span class="s">":\n"</span><span class="k2">;</span></td></tr><tr><td class="number">11</td><td>  cout <span class="k3">&lt;</span><span class="k3">&lt;</span> <span class="s">"\tTop-left corner at: "</span> <span class="k3">&lt;</span><span class="k3">&lt;</span> rect-&gt;left <span class="k3">&lt;</span><span class="k3">&lt;</span> <span class="s">","</span> <span class="k3">&lt;</span><span class="k3">&lt;</span> rect-&gt;top <span class="k3">&lt;</span><span class="k3">&lt;</span> <span class="s">"\n"</span><span class="k2">;</span></td></tr><tr><td class="number">12</td><td>  cout <span class="k3">&lt;</span><span class="k3">&lt;</span> <span class="s">"\tResolution: "</span> <span class="k3">&lt;</span><span class="k3">&lt;</span> <span class="k2">(</span>rect-&gt;right <span class="k3">-</span> rect-&gt;left<span class="k2">)</span> <span class="k3">&lt;</span><span class="k3">&lt;</span> <span class="s">"x"</span> <span class="k3">&lt;</span><span class="k3">&lt;</span> <span class="k2">(</span>rect-&gt;bottom <span class="k3">-</span> rect-&gt;top<span class="k2">)</span> <span class="k3">&lt;</span><span class="k3">&lt;</span> <span class="s">"\n\n"</span><span class="k2">;</span></td></tr><tr><td class="number">13</td><td>  </td></tr><tr><td class="number">14</td><td>        no<span class="k3">+</span><span class="k3">+</span><span class="k2">;</span></td></tr><tr><td class="number">15</td><td>&#160;</td></tr><tr><td class="number">16</td><td>  <span class="k1">return</span> <span class="k1">true</span><span class="k2">;</span></td></tr><tr><td class="number">17</td><td><span class="k2">}</span></td></tr><tr><td class="number">18</td><td>&#160;</td></tr><tr><td class="number">19</td><td><span class="k1">int</span> main<span class="k2">(</span><span class="k2">)</span></td></tr><tr><td class="number">20</td><td><span class="k2">{</span></td></tr><tr><td class="number">21</td><td>  EnumDisplayMonitors<span class="k2">(</span>NULL, NULL, <span class="k2">(</span>MONITORENUMPROC<span class="k2">)</span>callback, <span class="n">0</span><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">22</td><td><span class="k2">}</span></td></tr></tbody></table></div></div><p>

I knew it was EnumDisplaySomethings, I just picked the wrong one the first time around <img src="http://www.allegro.cc/forums/smileys/wink.gif" alt=";)" />. 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.</p><p>Perhaps someone from the forums with multiple monitors at hand could test it?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Jakub Wasilewski)</author>
		<pubDate>Fri, 18 May 2007 08:08:36 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
Monitor 1:<br />        Top-left corner at: 0,0<br />        Resolution: 1280x1024</p><p>Monitor 2:<br />        Top-left corner at: 1280,256<br />        Resolution: 1024x768</p><p>Monitor 3:<br />        Top-left corner at: -1280,0<br />        Resolution: 1280x1024
</p></div></div><p>
Works for me.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Matthew Leverton)</author>
		<pubDate>Fri, 18 May 2007 08:32:04 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
Monitor 1:<br />        Top-left corner at: 0,0<br />        Resolution: 1280x1024</p><p>Monitor 2:<br />        Top-left corner at: -1280,0<br />        Resolution: 1280x1024
</p></div></div><p>
Works here as well.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (MiquelFire)</author>
		<pubDate>Fri, 18 May 2007 18:51:18 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
Monitor 1:<br />        Top-left corner at: 0,0<br />        Resolution: 1680x1050
</p></div></div><p>

Works fine for one monitor.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (BAF)</author>
		<pubDate>Fri, 18 May 2007 19:16:13 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Sounds awesome. I&#39;ll put it to good use; thanks again.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (23yrold3yrold)</author>
		<pubDate>Sat, 19 May 2007 04:10:55 +0000</pubDate>
	</item>
</rss>
