GetWindowRgn function (winuser.h)

The GetWindowRgn function obtains a copy of the window region of a window. The window region of a window is set by calling the SetWindowRgn function. The window region determines the area within the window where the system permits drawing. The system does not display any portion of a window that lies outside of the window region

Syntax

int GetWindowRgn(
  [in] HWND hWnd,
  [in] HRGN hRgn
);

Parameters

[in] hWnd

Handle to the window whose window region is to be obtained.

[in] hRgn

Handle to the region which will be modified to represent the window region.

Return value

The return value specifies the type of the region that the function obtains. It can be one of the following values.

Return code Description
NULLREGION
The region is empty.
SIMPLEREGION
The region is a single rectangle.
COMPLEXREGION
The region is more than one rectangle.
ERROR
The specified window does not have a region, or an error occurred while attempting to return the region.

Remarks

The coordinates of a window's window region are relative to the upper-left corner of the window, not the client area of the window.

To set the window region of a window, call the SetWindowRgn function.

Examples

The following code shows how you pass in the handle of an existing region.


HRGN hrgn = CreateRectRgn(0,0,0,0);
int regionType = GetWindowRgn(hwnd, hrgn);
if (regionType != ERROR) 
{ 
/* hrgn contains window region */ 
}
DeleteObject(hrgn); /* finished with region */

Requirements

Requirement Value
Minimum supported client Windows 2000 Professional [desktop apps only]
Minimum supported server Windows 2000 Server [desktop apps only]
Target Platform Windows
Header winuser.h (include Windows.h)
Library User32.lib
DLL User32.dll
API set ext-ms-win-ntuser-draw-l1-1-2 (introduced in Windows 10, version 10.0.10240)

See also

Painting and Drawing Functions

Painting and Drawing Overview

SetWindowRgn