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!
Comments