Members

Technology Zones

IBM Learning Center

Articles

Hosted By

MaximumASP

Info

Rated
Read 31,718 times

Contents

Related Categories

Subclassing - Introduction

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!

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.