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)
Related articles
Related discussion
-
Run-time error '91'
by converter2009 (1 replies)
-
VB6 Runtime error 381 subsript out of range Error
by Uncle (2 replies)
-
passing and reading parameters from using Shell
by jigartoliya (0 replies)
-
Convert C++ code to VB6
by mawcot (4 replies)
-
listbox scrollbar
by Dennijr (10 replies)
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...
Pretty hacky functions... Try these:
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.
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!
http://www.vbaccelerator.com/home/VB/Code/Libraries/Subclassing/SSubTimer/article.asp
the link Download the SSubTmr project code (no DLL) (9kb) not working.
This thread is for discussions of Subclassing.