GetWindowLong 函数检索有关指定窗口的信息。 该函数还将指定偏移量处的 32 位(长)值检索到额外的窗口内存中。
LONG GetWindowLong( HWND hWnd, // 窗口句柄
int nIndex // 填特定的参数以获取改句柄的不同信息;
下面是第二个参数可以填的一些特定值
Value | Action |
---|---|
GWL_EXSTYLE | Retrieves the extended window styles. For more information, see CreateWindowEx. |
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 a handle to the application instance. |
GWL_HWNDPARENT | Retrieves a handle to 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. This value is initially zero. |
如果窗体是Dialog的话,还可以多添几个,主要是后三个是Dialog专用的。
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. |
常用的就是GWL_STYLE,他会返回改窗体的风格,对于不知道风格来加风格非常有用。
例子:比如我想给一个static窗口类添加一个可以显示图片的风格,却又不想改变他原有的风格,这就十分必要需要GetWindowLong这个函数了
LONG nStyle = GetWindowLong(hWndBMP, GWL_STYLE);
GetWindowLong SetWindowLong很重要
GetWindowLOng 就是获取原有的窗口风格
然后不改变原有风格的条件下还能加载
SetWindowLong(hWndBMP, GWL_STYLE,nStyle|SS_BITMAP);
当然,这里用到了SetWindowLong,要和GetWindowLOng对应起来使用.