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)

You might also like...

Comments

About the author

James Crowley

James Crowley United Kingdom

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

Interested in writing for us? Find out more.

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“A computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are, in short, a perfect match” - Bill Bryson