Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1632817
  • 博文数量: 584
  • 博客积分: 13857
  • 博客等级: 上将
  • 技术积分: 11883
  • 用 户 组: 普通用户
  • 注册时间: 2009-12-16 09:34

分类:

2011-01-21 14:00:42

GetWindowRgn Function

为什么我用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

Syntax

int GetWindowRgn(
__in  HWND hWnd,
__in  HRGN hRgn
);

Parameters

hWnd [in]

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

hRgn [in]

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 codeDescription
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 */


阅读(623) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~