GetClassLong Function

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

Platforms

Description & Usage

GetClassLong retrieves a single 32-bit value from the information about the window class to which the specified window belongs. The class's properties may not necessarily match perfectly with the actual properties of the window. This function can also retrieve a 32-bit value from the extra memory area associated with the window class.

Return Value

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

Visual Basic-Specific Issues

None.

Parameters

hWnd
A handle to a window which belongs to the class to read a property of.
nIndex
To retrieve a 32-bit value from the class's extra memory, set this to the zero-based offset of the byte to begin reading at. Valid values are 0 to the number of bytes of extra memory minus 4, inclusive. To retrieve a 32-bit property of the class, set this to one of the following flags specifying which 32-bit value to retrieve from the window class:
GCW_ATOM
Retrieve the atom which identifies the window class.
GCL_CBCLSEXTRA
Retrieve the size in bytes of the extra memory associated with the window class.
GCL_CBWNDEXTRA
Retrieve the size in bytes of the extra memory associated with each window belonging to the window class.
GCL_HBRBACKGROUND
Retrieve a handle to the brush used to paint the backgrounds of windows belonging to the class.
GCL_HCURSOR
Retrieve a handle to the cursor associated with the class.
GCL_HICON
Retrieve a handle to the icon associated with the class.
GCL_HICONSM
Retrieve a handle to the small icon associated with the class.
GCL_HMODULE
Retrieve a handle to the module which registered the class.
GCL_MENUNAME
Retrieve a pointer to the string identifying the name of the menu resource associated with the class.
GCL_STYLE
Retrieve the window styles associated with the class.
GCL_WNDPROC
Retrieve a pointer to the WindowProc hook function which acts as the window procedure for windows belonging to the window class.

Constant Definitions

Const GCW_ATOM = -32
Const GCL_CBCLSEXTRA = -20
Const GCL_CBWNDEXTRA = -18
Const GCL_HBRBACKGROUND = -10
Const GCL_HCURSOR = -12
Const GCL_HICON = -14
Const GCL_HMODULE = -16
Const GCL_MENUNAME = -8
Const GCL_STYLE = -26
Const GCL_WNDPROC = -24

Example

When the user clicks button Command1, draw the icon associated with the parent form window's class in the corner of the client area. This might not be the icon actually displayed by the window. Naturally, to use this exampe, 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 GetClassLong Lib "user32.dll" Alias "GetClassLongA" (ByVal hWnd As Long, _
	ByVal nIndex As Long) As Long
Public Const GCL_HICON = -14
Public Declare Function DrawIcon Lib "user32.dll" (ByVal hDC As Long, ByVal x As Long, ByVal y _
	As Long, ByVal hIcon As Long) As Long

' Place the following code inside a form window. ***

Private Sub Command1_Click ()
	Dim hIcon As Long   ' handle to the class's icon
	Dim retval As Long  ' return value
	
	' Retrieve a handle to the class's icon.
	hIcon = GetClassLong(Me.hWnd, GCL_HICON)
	' Draw that icon at coordinate (0,0) on Form1.
	retval = DrawIcon(Me.hDC, 0, 0, hIcon)
End Sub

See Also

GetWindowLong, SetClassLong

Category

Window Classes

Go back to the 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/getclasslong.html