Results 1 to 4 of 4

Thread: What is subclassing?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2000
    Posts
    95
    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.

  2. #2
    Hyperactive Member theman32x's Avatar
    Join Date
    May 2000
    Location
    New Jersey, USA
    Posts
    305

    Post it is ...

    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 ...

  3. #3
    Guest

    Another type.

    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.

  4. #4
    Frenzied Member
    Join Date
    Jan 2000
    Location
    Bellevue, WA, USA
    Posts
    1,357

    Talking Just off the top of my head....

    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:
    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
    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:
    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
    Finally, the code for the form sets the initial hWnd value, and the code for the buttons simply calls the two subroutines:
    Code:
    Private Sub Form_Load()
       gHW = Me.hwnd
    End Sub
    
    Private Sub Command1_Click()
       Hook
    End Sub
    
    Private Sub Command2_Click()
       Unhook
    End Sub
    ~seaweed

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width