what does subclassing mean?
i'm a newbie (2 years old) so go easy on me. because i'm really new (and i'm 2 years old) so make sure to not talk techinal becase of my age (and the fact that i'm a newbie) and i'm 2 years old.
Printable View
what does subclassing mean?
i'm a newbie (2 years old) so go easy on me. because i'm really new (and i'm 2 years old) so make sure to not talk techinal becase of my age (and the fact that i'm a newbie) and i'm 2 years old.
i'm not really sure i know what subclassing is but i think it has to do with being able to make ur program interact with other programs ... therefore u would need to subclass (some type of code) everything u know about the program u want UR program to interact with ... i think that's what it is ...
A class that is derived from a superclass by inheritance. The subclass contains all the features of the superclass, but may have new features added or redefine existing features.
SUBCLASSING
Subclassing is a technique that enables you to intercept Windows messages being sent to a form or control. By intercepting these messages, you can then write your own code to change or extend the behavior of the object. Subclassing can be complex, and a thorough discussion of it is beyond the scope of this book. The following example offers a brief illustration of the technique.
Important:
When Visual Basic is in break mode, you can't call vtable methods or AddressOf functions. As a safety mechanism, Visual Basic simply returns 0 to the caller of an AddressOf function without calling the function. In the case of subclassing, this means that 0 is returned to Windows from the WindowProc. Windows requires nonzero return values from many of its messages, so the constant 0 return may create a deadlock situation between Windows and the Visual Basic, forcing you to end the process.
This application consists of a simple form with two command buttons. The code is designed to intercept Windows messages being sent to the form and to print the values of those messages in the Immediate window.
The first part of the code consists of declarations for the API functions, constant values, and variables:
Next, two subroutines enable the code to hook into the stream of messages. The first procedure (Hook) calls the SetWindowLong function with the GWL_WNDPROC index to create a subclass of the window class that was used to create the window. It then uses the AddressOf keyword with a callback function (WindowProc) to intercept the messages and print their values in the Immediate window. The second procedure (Unhook) turns off subclassing by replacing the callback with the original Windows procedure.Code:Declare Function CallWindowProc Lib "user32" Alias _
"CallWindowProcA" (ByVal lpPrevWndFunc As Long, _
ByVal hwnd As Long, ByVal Msg As Long, _
ByVal wParam As Long, ByVal lParam As Long) As Long
Declare Function SetWindowLong Lib "user32" Alias _
"SetWindowLongA" (ByVal hwnd As Long, _
ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Public Const GWL_WNDPROC = -4
Global lpPrevWndProc As Long
Global gHW As Long
Finally, the code for the form sets the initial hWnd value, and the code for the buttons simply calls the two subroutines:Code:Public Sub Hook()
lpPrevWndProc = SetWindowLong(gHW, GWL_WNDPROC, _
AddressOf WindowProc)
End Sub
Public Sub Unhook()
Dim temp As Long
temp = SetWindowLong(gHW, GWL_WNDPROC, _
lpPrevWndProc)
End Sub
Function WindowProc(ByVal hw As Long, ByVal uMsg As _
Long, ByVal wParam As Long, ByVal lParam As Long) As _
Long
Debug.Print "Message: "; hw, uMsg, wParam, lParam
WindowProc = CallWindowProc(lpPrevWndProc, hw, _
uMsg, wParam, lParam)
End Function
Code:Private Sub Form_Load()
gHW = Me.hwnd
End Sub
Private Sub Command1_Click()
Hook
End Sub
Private Sub Command2_Click()
Unhook
End Sub