|
||
|
Subclassing and Hooking with Machine Code ThunksEliminate the .bas modules for AddressOf tasks for easier to manageable subclassing and hooking code. VB's AddressOf is limited in that it can only provide an address to a function within a module, and not one in a class. This makes doing many things with it harder. However, there is a way of getting a callback to a class function, although you need to know a little assembler to do it. Don't worry if you don't though - here Paul Caton presents some fantastic reusable code showing how to subclass or hook any Window without modules using this technique. What's In The DownloadThe download contains five different samples:
Subclassing Without Modules - A Quick OverviewThis describes the steps need to set a subclass and demonstrates using the code to respond to the WM_MINMAXINFO message to prevent a form being made smaller than a certain size. First add cSubClass.cls from the download and then reference the included WinSubHook.TLB (Windows/Subclass/Hook/Timer interface 1.4). Once this is done, you start subclassing by:
The World Is Never EnoughAlthough this is by far the best subclassing sample I've seen, I would note that at the current release you cannot subclass the same window from more than one class without causing a crash. As long as you're careful about how you apply the subclass you will be fine, but if you even inadvertently start subclassing the same window twice (the usual way this happens is when you use the subclasser in a user control or a DLL, and the messages you need to receive are send to the container or parent of the object, and then you put two instances of the control on the same container - see Subclassing without the crashes for more details) you will soon start to see random crashes. On my system this manifests itself as the exciting vanishing window syndrome! There are two possible ways to stop this happening: use ComCt32.DLL v6.0 subclassing (fixes all problems; the downside is it requires new ASM code and only works on XP) or attempt to use the Windows Properties database again. I will keep you posted. More InformationIf you're still using VB6 then I would definitely recommend getting hold of a copy of Matt Currland's excellent book "Advanced Visual Basic 6". Although it was unfortunately published just that wee bit too late as the .NET framework was occupying everyone else's minds, it nevertheless demonstrates conclusively how so many of VB's issues have a solution. If the entirety of Matt's ideas had been included in VB6 in a controllable way then none of us would have had so much to complain about when VB6 was released (not that I would complain about the .NET framework though; it is clearly a fantastic thing and replacing COM is something more of an undertaking than just fixing a few annoyances with VB. Mind you, it'll be much more persuasive if Microsoft really do release a .NET MS Office and IE). The book describes the thunking technique (albeit briefly) but its certainly worth your money.
|
|
|