Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>My first thoughts were listed below but if, as you state, you're certain that <code>GetWindowRect</code> is returning incorrect values, see <em>RESOLUTION</em> further down.</p> <hr> <p>"What's wrong with <code>GetSystemMetrics(SM_CXBORDER)</code> and <code>GetSystemMetrics(SM_CYBORDER)</code>?</p> <p>The method you're using seems a very roundabout way of doing it and, if you can call <code>GetWindowRect()</code>, I'm pretty certain you can call <a href="http://msdn.microsoft.com/en-us/library/ms724385%28VS.85%29.aspx" rel="nofollow noreferrer"><code>GetSystemMetrics()</code></a> as well.</p> <p>One other possibility is to use <a href="https://msdn.microsoft.com/en-us/library/ms633519.aspx" rel="nofollow noreferrer"><code>GetWindowRect</code></a> to get the entire bounding rectangle for the window and <a href="http://msdn.microsoft.com/en-us/library/ms633503%28VS.85%29.aspx" rel="nofollow noreferrer"><code>GetClientRect</code></a> to get the bounding rectangle for the client (non-border) area. </p> <p>This <em>should</em> give you something like <code>(100,200),(1000,900)</code> and <code>(112,227),(988,888)</code> respectively and you can work out the top border as <code>227-200</code>, bottom as <code>900-888</code>, left as <code>112-100</code> and right as <code>900-888</code> (27,12,12,12).</p> <hr> <p><em>RESOLUTION:</em></p> <p>A bit of investigation turns up <a href="http://social.msdn.microsoft.com/Forums/en-US/windowsuidevelopment/thread/6c1c67a9-5548-4e9b-989f-c7dbac0b1375/" rel="nofollow noreferrer">this</a>. It's a thread from 2006 stating that you might not get the correct values from <code>GetWindowsRect</code>. The thread that pointed me to this stated:</p> <blockquote> <p>Apps under Vista that are not linked with WINVER=6 will receive a misleading set of values here, that do not account for the extra padding of "glass" pixels Vista Aero applies to the window. This appears to happen even in Aero Basic (without Glass) to retain sizing consistency. The workaround (if you don't want to set WINVER=6) seems to be to dynamically bind to dwmapi.dll and use GetProcAddress() to obtain the DwmGetWindowAttribute() function, and call it with the DWMWA_EXTENDED_FRAME_BOUNDS argument to request the genuine window frame dimensions.</p> </blockquote> <p>So basically, use something like (you may have to use ctypes to do this from Python):</p> <pre><code>RECT r; HRESULT stat = DwmGetWindowAttribute ( hwnd, DWMWA_EXTENDED_FRAME_BOUNDS, &amp;r, sizeof(r)); </code></pre> <p>and that should give you the correct bounding rectangle.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload