全部博文(584)
分类:
2011-01-21 14:00:42
为什么我用GetWindowRgn函数老是返回0,我在各种区域的窗口上都是个了。比如说如下语句:
HRGN hrgn = CreateRoundRectRgn( 0,0,100,100,10,10);
SetWindowRgn( hWnd, hrgn );
HRGN h;
GetWindowRgn( hWnd, h );
是不是还要设置一些别的东西?
你在调用GetWindowRgn之前应该先创建一个HRGN(哪怕这个HRGN是空的),你的代码应该做如下修改:
HRGN hrgn = CreateRoundRectRgn( 0,0,100,100,10,10);
SetWindowRgn( hWnd, hrgn );
HRGN h;
h=CreateRectRgn(0,0,0,0);
GetWindowRgn( hWnd, h );
这样你在h中就应该得到了和hrgn一样的区域。
The GetWindowRgn function obtains a copy of the window region of a window. The window region of a window is set by calling the 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
int GetWindowRgn(
__in HWND hWnd,
__in HRGN hRgn
);
Handle to the window whose window region is to be obtained.
Handle to the region which will be modified to represent the window region.
The return value specifies the type of the region that the function obtains. It can be one of the following values.
Return code | Description |
---|---|
|
The region is empty. |
|
The region is a single rectangle. |
|
The region is more than one rectangle. |
|
The specified window does not have a region, or an error occurred while attempting to return the region. |
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.
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 */