Library tutorials & articles
Subclassing
Introduction
If you have no experience on 'windows messages', I recommend that you read my article on sending messages, before you read this one.
Visual Basic is like a worried mother at times. It shields you from the rough and tumble of the real world. However, sometimes you want to get out there and can't. Each control has a selected number of events and properties. If you were programming in C++, there would be many more such events. When you move your mouse over a menu item, a message is sent to the VB framework. However, as there is no MouseOver event for menu items, VB it ignores it and does not pass it on to you. Subclassing is all about catching these messages using Windows API, before Visual Basic gets its hands on them and chucks most of them in the bin. Each message has a unique number, and most are listed as constants in the API Text viewer, and normally start with WM_ .
Please read the following warnings, but don't let them put you off, as Subclassing opens up a whole new world. Alternatively, you can use the SSUBTMR.DLL file, and not have to worry about them at all!
WARNING 1!
Please note before continuing that when you subclass messages, you have 'signed'
an agreement with windows, so that windows will pass on all messages to you. In order to
terminate this agreement, you need to un-subclass your program. This occurs in the
Form_Unload event (when you press the X button). However, if you use the stop button on the toolbar in
Visual Basic, , it will not call this procedure. Visual Basic, and your
program will crash, and you will lose any unsaved work.
It is advisable to always save your work before running your application. To avoid temptation, you can remove the stop icon from your VB toolbar using the Customize Menu command.
WARNING 2!
When you receive a warning saying that the changes you have made will reset your project,
press Cancel. Pressing yes will end your program, and is the same as pressing the stop
button (see above)
WARNING 3!
Do not enter any breakpoints into the WindowProc procedure, or try to debug it during run
time, as Visual Basic will crash again!
Related articles
Related discussion
-
Problem with migration to C# (CoCreateInstanceEx)
by LRollison (1 replies)
-
VB6 Problem Creating Shortcuts
by rb1177 (0 replies)
-
how can i open a file
by kyawswarhtun (0 replies)
-
how to save any one form what i want?
by blackguy (5 replies)
-
Build an MP3 Player
by soybees (4 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.