Jump to content
  • Advertisement
  • entries
  • comments
  • views

Some (somewhat crappy) code

Sign in to follow this  
Emmanuel Deloget


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.


typedef enum

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);
if (rgntype == NULLREGION) {
prevhwnd = hwnd;
hwnd = ::GetNextWindow(prevhwnd, GW_HWNDPREV);

if (::EqualRgn(hrgnwin, hrgnwincpy)) {
rescode = NOCOVERAGE;
} else {


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 ;)
Sign in to follow this  


Recommended Comments

There are no comments to display.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!