Windows – Why does GetWindowRgn fail on Vista

winapiwindows-vista

I'm writing a program that uses SetWindowRgn to make transparent holes in a window that belongs to another process. (This is done only when the user explicitly requests it.)

The program has to assume that the target window may already have holes which need to be preserved, so before it calls SetWindowRgn, it calls GetWindowRgn to get the current region, then combines the current region with the new one and calls SetWindowRgn:

HRGN rgnOld = CreateRectRgn ( 0, 0, 0, 0 );
int regionType = GetWindowRgn ( hwnd, rgnOld ); 

This works fine in XP, but the call to GetWindowRgn fails in Vista. I've tried turning off Aero and elevating my thread's privilege to SE_DEBUG_NAME with AdjustTokenPrivileges, but neither helps.

GetLastError() doesn't seem to return a valid value for GetWindowRgn — it returns 0 on one machine and 5 (Access denied) on another.

Can anyone tell me what I'm doing wrong or suggest a different approach?

Best Answer

Are you sure your window has a region? Most top-level windows in XP do, simply because the default theme uses them for round corners... but this is still a bad assumption to be making, and may very well not hold once you get to Vista.

If you haven't set a region yet, and the call fails, use a sensible default (the window rect) and don't let it ruin your life. Now, if SetWindowRgn() fails...

Related Topic