Where do you want to go next?here's for you :)about homeopathyassorted rantsVB and subclassingVB, screensavers and security concernsLet the Skriptkiddiots play...VB and pointersVB and the Windows shellVB and multitaskingVisual Basiclibrariessnakeoil and blatant liesZoneAlarmeSafefirewall basicsabout harmful codeIn Commerce' Service - sniffersabout spywarecookie jarabout PGPabout privacymain page

Subclassing


I won't say much of that here, at least not until I get some sample-code ready.


But since it took me a while to get behind the curtain (that was before the MSDN), I'll give you some hints.


When Windows talks to a window (or a thread), it uses a kind of calling-tube. It's a semaphore. No, not the flagpole with arms, but it works alike.


When you subclass you do nothing else than tapping the line (reading other's smoke-signs or something like that):

[Caller] -dumping-> [your function] -passing on -> [original

Receiver]


The Caller sends a message to the original receiver, but before it reaches it, you can process the messages on your own. Don't forget to pass those on that you don't want to get stuck (like WM_QUIT) :)


To subclass you first write a function in a module that takes the same values as the original function. Look at DefWindowProc in the MSDN to see what's needed. After this you call SetWindowLong and pass it the AddressOf your function. Keep the returned value in a safe place, you'll need it to un-subclass and to pass on the messages.


Now your function gets the messages first and you pick up those you want. No PeekMessage or GetMessage, you'll get them anyway. Now you can react to each and every message. Some you'll pass on, since you don't want to process them, others you'll pass on anyway, as you only needed the information, and still others you'll hand over unprocessed.


This sending-on is done with CallWindowProc. The function takes the orignal values of SendMessage (and all siblings of the function) plus the original long (the returned long of SetWindowLong).


You certainly have guessed by now that this long is but a pointer to the functions, haven't you?


So, if you are done with subclassing, don't forget to call SetWindowLong again, this time with the original long. You wouldn't want the message-queue interrupted and pointing to never-come-back :)


Here's a thing I'm tackling: it should be possible to subclass Windows itself? It should be possible to iterate through all windows, subclass them, and get each and every message.


Just imagine capturing the WM_MOVE and playing a sound for it... Win could become almost as smart as KDE. *sigh* If you have a clue, mail me :)