How to get only the visible part of the window (Windows, gdi32, user32, etc.)

I want to get only the visible part of the window in the windows, as a region.

You want to get only the area that the user sees. Programmatically, of course. Here is an example. I have the following window composition:

+------------------------------------------+
 |                                          |
 |           +=============+                |
 |           |             |                |
 |           |    A   +--------------------------+
 |           |        |                          |
 |    C      |        |             B            |
 |           |        +--------------------------+
 |           |             |                |
 +-----------|             |----------------+
             |             |
             +-------------+

Say that I am only interested in window A. Then I need a handle to the area that will look like this:

          +=============+                
          |             |                
          |    A  +-----+
          |       |                          
          |       |                         
          |       +-----+
          |             |                
          |             |
          |             |
          +-------------+

Alternatively, I should be able to get the area of ​​any other window as follows.

So far I have used this guide: http://blogs.msdn.com/b/oldnewthing/archive/2003/09/02/54758.aspx

, GetClipBox 0, 1, 2 3, , , 0 → , 1 NULLREGION ( rgn ), 2 → SIMPLEREGION 3 COMPLEXREGION, .

: ?

( ​​)

COMPLEXREGION ( , ) , . , :

http://www.codeguru.com/forum/archive/index.php/t-126543.html

( ​​)

, A PolyPath , ?

JNA (Java), , # .VB- .

.

+3
2

, . , .

, Windows "" ( Aero , , ).

, , ( , Aero).

DPI, Windows "" , DPI.

, "" , Alt-Tab Flip3D Aero... , , Vista Windows 7 DWM , .:)

+2

, . .

HRGN GetVisibleRegion(HWND hwnd)
{   
    //Store the region of window hwnd
    RECT hwndRect={0,0,0,0};
    ::GetWindowRect(hwnd,&hwndRect);
    HRGN rgn=::CreateRectRgn(hwndRect.left,hwndRect.top,hwndRect.right,hwndRect.bottom);


    //HWND hParentWnd=::GetParent(hwnd);
    HWND hParentWnd=::GetAncestor(hwnd,GA_PARENT);
    HWND hChildWnd=hwnd;
    //until we reaches desktop window
    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};
            //Other window overlapping with hwnd
            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=::GetParent(hParentWnd);
        hParentWnd=::GetAncestor(hParentWnd,GA_PARENT);
    }   
    return rgn;
}
0

Source: https://habr.com/ru/post/1775215/


All Articles