现在的位置: 首页 > 综合 > 正文

GetWindowLong函数详解

2012年05月12日 ⁄ 综合 ⁄ 共 2349字 ⁄ 字号 评论关闭

函数功能描述:用这个函数能够获得指定窗口的信息

函数原型:
LONG GetWindowLong( HWND hWnd,int nIndex )

参数:
hWnd:指定窗口的句柄
nIndex:需要获得的信息的类型
     值            功能

nIndex取值如下:
GWL_EXSTYLE    得到扩展的窗口风格
GWL_STYLE      得到窗口风格
GWL_WNDPROC    得到窗口回调函数的地址,或者句柄。得到后必须使用CallWindowProc函数来调用
GWL_HINSTANCE  得到应用程序运行实例的句柄
GWL_HWNDPARENT 得到父窗口的句柄
GWL_ID         得到窗口的标识符
GWL_USERDATA   得到和窗口相关联的32位的值(每一个窗口都有一个有意留给创建窗口的应用程序是用的32位
               的值)

当hWnd标识一个对话框时可以使用下面的值
Value Action
DWL_DLGPROC   得到对话框回调函数的地址,或者句柄。得到后必须使用CallWindowProc函数来调用
DWL_MSGRESULT 得到对话框回调函数中消息处理过程的返回值
DWL_USER      得到额外的应用程序私有信息,如一些句柄和指针等

返回值:
成功时,返回一个请求的32位的值
失败时,返回0,可以使用GetLastError来取得错误信息

 MSDN的原文:

GetWindowLong

The GetWindowLong function retrieves information about the specified window. The function also retrieves the 32-bit (long) value at the specified offset into the extra window memory of a window.

LONG GetWindowLong(
  HWND hWnd,  // handle of window
  int nIndex  // offset of value to retrieve
);
 

Parameters

hWnd
Handle to the window and, indirectly, the class to which the window belongs.
nIndex
Specifies the zero-based offset to the value to be retrieved. Valid values are in the range zero through the number of bytes of extra window memory, minus four; for example, if you specified 12 or more bytes of extra memory, a value of 8 would be an index to the third 32-bit integer. To retrieve any other value, specify one of the following values:

Value Action
GWL_EXSTYLE Retrieves the extended window styles.
GWL_STYLE Retrieves the window styles.
GWL_WNDPROC Retrieves the address of the window procedure, or a handle representing the address of the window procedure. You must use the CallWindowProc function to call the window procedure.
GWL_HINSTANCE Retrieves the handle of the application instance.
GWL_HWNDPARENT Retrieves the handle of the parent window, if any.
GWL_ID Retrieves the identifier of the window.
GWL_USERDATA Retrieves the 32-bit value associated with the window. Each window has a corresponding 32-bit value intended for use by the application that created the window.

The following values are also available when the hWnd parameter identifies a dialog box:

Value Action
DWL_DLGPROC Retrieves the address of the dialog box procedure, or a handle representing the address of the dialog box procedure. You must use the CallWindowProc function to call the dialog box procedure.
DWL_MSGRESULT Retrieves the return value of a message processed in the dialog box procedure.
DWL_USER Retrieves extra information private to the application, such as handles or pointers.

Return Values

If the function succeeds, the return value is the requested 32-bit value.

If the function fails, the return value is zero. To get extended error information, callGetLastError.

抱歉!评论已关闭.