Windows API Guide: GetParent Function


Declare Function GetWindowLong Lib "user32.dll" Alias "GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long) As Long

Platforms

  • Windows 95: Supported.
  • Windows 98: Supported.
  • Windows NT: Requires Windows NT 3.1 or later.
  • Windows 2000: Supported.
  • Windows CE: Requires Windows CE 1.0 or later.

Description & Usage

GetWindowLong retrieves a 32-bit value from the information about a window. This function can also read a 32-bit value from the block of extra memory given to the window, if one exists.

Return Value

If an error occured, the function returns 0 (use GetLastError to get the error code). If successful, the function returns the 32-bit value which was retrieved.

Visual Basic-Specific Issues

None.

Parameters

hWnd
A handle to the window to retrieve a 32-bit value from.
nIndex
To get a 32-bit value from the window's extra memory block, this is the zero-based offset of the byte to begin reading from. Valid values range from 0 to the size of the extra memory block in bytes minus four. To get a 32-bit value from the properties of the window, this is one of the following flags specifying which piece of information to retieve:
GWL_EXSTYLE
Retrieve the extended window styles of the window.
GWL_HINSTANCE
Retrieve a handle to the owning application's instance.
GWL_HWNDPARENT
Retrieve a handle to the parent window, if any.
GWL_ID
Retrieve the identifier of the window.
GWL_USERDATA
Retrieve the application-defined 32-bit value associated with the window.
GWL_STYLE
Retrieve the window styles of the window.
GWL_WNDPROC
Retrieve a pointer to the WindowProc hook function acting as the window's procedure.
If the window happens to be a dialog box, this could also be one of the following flags:
DWL_DLGPROC
Retrieve a handle to the WindowProc hook function acting as the dialog box procedure.
DWL_MSGRESULT
Retrieve the return value of the last message processed by the dialog box.
DWL_USER
Retrieve the application-defined 32-bit value associated with the dialog box.

Constant Definitions

Const GWL_EXSTYLE = -20 Const GWL_HINSTANCE = -6 Const GWL_HWNDPARENT = -8 Const GWL_ID = -12 Const GWL_STYLE = -16 Const GWL_USERDATA = -21 Const GWL_WNDPROC = -4 Const DWL_DLGPROC = 4 Const DWL_MSGRESULT = 0 Const DWL_USER = 8

Example

When the user clicks button Command1, determine if its parent window has a maximize button or not by checking its window style. To use this example, you must first place a command button named Command1 on a form window.

' This code is licensed according to the terms and conditions listed here. ' Declarations and such needed for the example: ' (Copy them to the (declarations) section of a module.) Public Declare Function GetWindowLong Lib "user32.dll" Alias "GetWindowLongA" (ByVal hWnd As Long, _ ByVal nIndex As Long) As Long Public Const GWL_STYLE = -16 Public Const WS_MAXIMIZEBOX = &H10000 ' *** Place the following code inside a form window. *** Private Sub Command1_Click () Dim styles As Long  ' receives window styles of Form1 ' Get the window styles of Form1. styles = GetWindowLong(Me.hWnd, GWL_STYLE) ' Determine if a maximize box exists or not. If (styles And WS_MAXIMIZEBOX) = WS_MAXIMIZEBOX Then Debug.Print "The form window has a maximize box." Else Debug.Print "The form window does not have a maximize box." End If End Sub

See Also

GetClassLong, SetWindowLong

Category

Window Classes

Go back to the alphabetical Function listing.
Go back to the Reference section index.


Last Modified: October 29, 2000
This page is copyright © 2000 Paul Kuliniewicz. Copyright Information Revised October 29, 2000
Go back to the Windows API Guide home page.
E-mail: vbapi@vbapi.com Send Encrypted E-Mail
This page is at http://www.vbapi.com/ref/g/getwindowlong.html



Windows API Guide
Windows API Guide - Reference - Volume 1: Version 3.0 For the MS-DOS and PC-DOS Operating Systems
ISBN: B001V0KQIY
EAN: N/A
Year: 1998
Pages: 610

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net