Send a suggestion!

We're building a brand new version of the site, and we'd love to hear your ideas

Members

Technology Zones

IBM Learning Center

Articles

Hosted By

MaximumASP

Info

Rated
Read 32,162 times

Contents

Related Categories

Subclassing - Using SSubTmr

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)

James first started writing tutorials on Visual Basic in 1999 whilst starting this website (then known as VB Web). Since then, the site has grown rapidly, and James has written numerous tutorials, articles and reviews on VB, PHP, ASP and C#. In October 2003, James formed the company Developer Fusion Ltd, which owns this website, and also offers various development services. In his spare time, he's a 3rd year undergraduate studying Computer Science in the UK. He's also a Visual Basic MVP.

Comments

  • GetLowWord() and GetHighWord()

    Posted by HyperHacker on 25 Feb 2004

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

  • Mr. Crowley copies source code!

    Posted by alpine on 08 Aug 2003

    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!

  • Posted by James Crowley on 07 Mar 2003

    http://www.vbaccelerator.com/home/VB/Code/Libraries/Subclassing/SSubTimer/article.asp

  • link not working

    Posted by gautam on 07 Mar 2003

    the link [b]Download the SSubTmr project code (no DLL) (9kb) [/b] not working.