Note that there are some explanatory texts on larger screens.

plurals
  1. POdetermining whether a window is in desktop bounds c++
    primarykey
    data
    text
    <p>I wrote some code to determinate whether a certain window is inside the desktop bounds.<br /> Somehow, it doesn't work. For every window, regardless whether it is inside or outside the desktop, <code>false</code> is returned. Something is terribly wrong here, but after staring at this piece of code for 3 hours now, I still don't know where the problem is. If I try to read a RECT struct from the pointer sent in the PMSG's WPARAM, I get a AccessViolationException. Why is this happening?</p> <p>My code look like this, and always returns false:</p> <pre><code>static bool IsInBounds(HWND window) { DEVMODE d; d.dmSize = sizeof(DEVMODE); BOOL b = EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &amp;d); if(b == FALSE) { PostMessage(FindWindow(NULL, L"Window #1"), RegisterWindowMessage(L"FMSG"), (WPARAM)window, NULL); } RECT R; GetWindowRect(window, &amp;R); POINT p = POINT(); p.x = (LONG)d.dmPelsWidth; p.y = (LONG)d.dmPelsHeight; PostMessage(FindWindow(NULL, L"Window #1"), RegisterWindowMessage(L"PMSG"), (WPARAM)&amp;R, d.dmPelsWidth); if(R.right &lt; 0 || R.bottom &lt; 0 || R.left &gt; (LONG)d.dmPelsWidth || R.top &gt; (LONG)d.dmPelsHeight) { return false; } return true; } </code></pre> <p>EDIT: after calling IsInBounds, which returned an error number 1400 (Invalid window handle), but before returning from the hook callback, I called <code>IsWindow(window)</code>, to see, if my handle is still valid. The truth is: it <strong>is in deed</strong> a valid handle! How can it be that GetWindowRect says its an invalid handle?</p> <p>EDIT: I tried MonitorFromWindow as sujested, but it returned NULL, and calling GetLastError resulted in error no. 1400, which is already familiar to me. Looks like MonitorFromWindow implicitly calls GetWindowRect. I don't care about the size, but is there <strong>another</strong> way to get window coordinates from a handle?</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.
 

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