• entries
109
175
• views
117016

# Some (somewhat crappy) code

606 views

Yes. Nothing related to our main activity, but here is some code to answer a question: how to know wether your window is partially/totally overlapped by another window. The code is actually quite - well, how to say that without being blunt? - stupid.

/* getwindowcoverage.c -- version 1, Feb. 15th, 2005  Copyright (C) 2005 Emmanuel Deloget  This software is provided 'as-is', without any express or implied  warranty.  In no event will the authors be held liable for any damages  arising from the use of this software.  Permission is granted to anyone to use this software for any purpose,  including commercial applications, and to alter it and redistribute it  freely, subject to the following restrictions:  1. The origin of this software must not be misrepresented; you must not     claim that you wrote the original software. If you use this software     in a product, an acknowledgment in the product documentation would be     appreciated but is not required.  2. Altered source versions must be plainly marked as such, and must not be     misrepresented as being the original software.  3. This notice may not be removed or altered from any source distribution.    This license text is based upon the zlib license text.*/#include typedef enum {  NOCOVERAGE,  PARTIALCOVERAGE,  TOTALCOVERAGE} WINDOWCOVERAGE;WINDOWCOVERAGE GetWindowCoverage(HWND toplevel){  RECT    wrect;  HRGN    hrgnwin;  HRGN    hrgnwincpy;  HWND    hwnd;  HWND    prevhwnd;  HRGN    otherrgn;  RECT    otherrect;  int      rgntype;  int      rescode;  ::GetWindowRect(toplevel, &wrect);  hrgnwin = ::CreateRectRgn(wrect.left, wrect.top, wrect.right, wrect.bottom);  hrgnwincpy = ::CreateRectRgn(wrect.left, wrect.top, wrect.right, wrect.bottom);  prevhwnd = toplevel;  hwnd = ::GetNextWindow(prevhwnd, GW_HWNDPREV);  while (hwnd) {    if (::IsWindowVisible(hwnd)) {      ::GetWindowRect(hwnd, &otherrect);      otherrgn = ::CreateRectRgn(otherrect.left, otherrect.top, otherrect.right, otherrect.bottom);      rgntype = ::CombineRgn(hrgnwin, hrgnwin, otherrgn, RGN_DIFF);      ::DeleteObject(otherrgn);      if (rgntype == NULLREGION) {        ::DeleteObject(hrgnwin);        ::DeleteObject(hrgnwincpy);        return TOTALCOVERAGE;      }    }    prevhwnd = hwnd;    hwnd = ::GetNextWindow(prevhwnd, GW_HWNDPREV);  }  if (::EqualRgn(hrgnwin, hrgnwincpy)) {    rescode = NOCOVERAGE;  } else {    rescode = PARTIALCOVERAGE;  }  ::DeleteObject(hrgnwin);  ::DeleteObject(hrgnwincpy);  return rescode;}

The pure Win32 code works correctly, but it only tests other top level windows. It means that it is more "is my application hidden by another application" function.

I already gave this code in a past gdnet thread (I believe it was during January).

Hope you like it ;)

There are no comments to display.