Some (somewhat crappy) code

posted in Computer food
Published February 15, 2005
Advertisement
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).

Comments are welcome :)

Hope you like it ;)
0 likes 0 comments

Comments

Nobody has left a comment. You can be the first!
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Advertisement
Advertisement