, .
.
HRGN GetVisibleRegion(HWND hwnd)
{
RECT hwndRect={0,0,0,0};
::GetWindowRect(hwnd,&hwndRect);
HRGN rgn=::CreateRectRgn(hwndRect.left,hwndRect.top,hwndRect.right,hwndRect.bottom);
HWND hParentWnd=::GetAncestor(hwnd,GA_PARENT);
HWND hChildWnd=hwnd;
while(hChildWnd!=NULL && hChildWnd!=GetDesktopWindow())
{
HWND topWnd=::GetTopWindow(hParentWnd);
do
{
if(topWnd==hChildWnd)
{
break;
}
RECT topWndRect={0,0,0,0}; ::GetWindowRect(topWnd,&topWndRect);
RECT tempRect={0,0,0,0};
if(::IsWindowVisible(topWnd) && !::IsIconic(topWnd) && IntersectRect(&tempRect,&topWndRect,&hwndRect)!=0)
{
HRGN topWndRgn=::CreateRectRgn(topWndRect.left,topWndRect.top,topWndRect.right,topWndRect.bottom);
::CombineRgn(rgn,rgn,topWndRgn,RGN_DIFF);
::RealDeleteObject(topWndRgn);
}
topWnd = GetNextWindow(topWnd, TWO);
}while(topWnd!=NULL);
hChildWnd=hParentWnd;
hParentWnd=::GetAncestor(hParentWnd,GA_PARENT);
}
return rgn;
}