Library tutorials & articles

Subclassing

Using SSubTmr

The SSUBTMR.DLL is a modified version of HardCore Visual Basic's SUBTIMER.DLL, with a few revisions and bug patches by VB Accelerator. To download it, click here. To use it, do the following:

1) Add the following code to the general declarations section of the form you want to subclass

Implements ISubclass
Private m_emr As EMsgResponse
Private bSubclassing As Boolean

2) Also add the declarations of any messages you want to include. For example:

Public Const WM_SYSCOMMAND = &H112

3) For each message you want to subclass, you need to add a call to AttachMessage and DetachMessage. An example is given, and it uses the following syntax:

AttachMessage Form with the Implements statement, Form.hwnd you want to subclass's property, Message you want to subclass

For example:

AttachMessage Me, hwnd, WM_OTHERWINDOWDESTROYED

So, add the following procedures.

Public Sub pAttachMessages()
    m_emr = emrPreprocess
    '// delete this example, and add your own
    AttachMessage Me, hwnd, WM_OTHERWINDOWDESTROYED
    bSubclassing = True
End Sub
Private Sub pDetachMessages()
   If (bSubclassing) Then
        '// delete this example, and add your own
        DetachMessage Me, hwnd, WM_OTHERWINDOWDESTROYED
        bSubclassing = False
   End If
End Sub

4) Then, add the following code:

Private Property Let ISubclass_MsgResponse(ByVal RHS As SSubTimer.EMsgResponse)
    '// this proc is not really needed, but you still need to add it!
End Property

Private Property Get ISubclass_MsgResponse() As SSubTimer.EMsgResponse
    '// Tell the subclasser what to do for this message (here we do all processing):
    ISubclass_MsgResponse = emrPreprocess
End Property

Private Function ISubclass_WindowProc(ByVal hwnd As Long, ByVal iMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    Select Case iMsg
    '// add Case statements for each message you wanted subclassed:
    Case WM_MESSAGE1
        '// enter what you want to do when WM_MESSAGE1 occurs
    Case WM_MESSAGE2
        '// enter what you want to do when WM_MESSAGE2 occurs ...
    End Select
End Function

There is also an example available for download from VB Accelerator: Download the SSubTmr project code (no DLL) (9kb)

Comments

  1. 25 Feb 2004 at 20:18

    Pretty hacky functions... Try these:


    Code:
    Public Function GetLowWord(Word As Long) as Long
      GetLowWord = Word Mod 65536
    End Function


    Public Function GetHighWord(Word As Long)
       GetHighWord = (Word \ 65536) Mod 65536
    End Function



    Those will chop off the 1st/2nd and 3rd/4th bytes respectively using pure math. Much faster and more universal.

  2. 08 Aug 2003 at 22:28

    Hummmm.....  This code looks surprisingly like the code in the GETMINMAXINFO example at  http://www.mvps.org/vbvision/  Right down to the exact same comments!  Coincidence?  You be the judge!

  3. 07 Mar 2003 at 06:31
  4. 07 Mar 2003 at 05:42

    the link Download the SSubTmr project code (no DLL) (9kb) not working.

  5. 01 Jan 1999 at 00:00

    This thread is for discussions of Subclassing.

Leave a comment

Sign in or Join us (it's free).

James Crowley James first started this website when learning Visual Basic back in 1999 whilst studying his GCSEs. The site grew steadily over the years while being run as a hobby - to a regular monthly audience ...

Related discussion

Related podcasts

  • Christian Beauclair

    14 mai 2008 (�mission #0074) ::.Christian Beauclair: Stratégies de migration VB6 vers .NET Nous discutons avec Christian Beauclair des stratégies de migration VB6 vers .NET. Entre autres, nous discutons comment utiliser le "VB 6 Code Advisor" et le "Interop Forms Toolkit" pour ajouter la puiss...

We'd love to hear what you think! Submit ideas or give us feedback