Crazy D
May 30th, 2000, 08:21 PM
Hook and subclass are basically the same (just a name....) (although I never heard someone say keyboardsubclass (where they did say keyboardhook).
It basically means intercept window messages before they reach the target. For instance, you can subclass your form, which means that the function you created to handle the windows messages (your window proc, or subclass proc), receives the messages send to your window. Note that *all* messages are send to that function. You decide which messages you want to catch (for instance the WM_ACTIVATE, which are send both when you're app gets the focus, as when it looses the focus). Depending on the message, you do something and send it to the original window proc, or not (which can cause funny things ;-).
The kewl thing of this is that you can either get events which you wont get otherwise (WM_ACTIVATE doesn't have a VB-event), or you can make things go smoother (for instance, if you want your app to be not be able to be resized smaller then a certain size, you can do it in the form_resize event, but that looks ugly. If you subclass the form, you handle the message before VB raises the resize event, and then you can make it look kewl (if you have VB running in the SDI mode, the main VB window cannot be resized smaller then it's initial height, that's what you can do with subclassing). Or you can do kewl things like drawing your custom form caption.
I talk about a form here, but it counts for *every* object which has a hWnd property (you can subclass a textbox to remove the right mouse menu, or to make sure you can't paste in the textbox).
A hook is, from what I've seen, used in "keyboard hook", which is intercepting the keyboard events before the active application receives them (so you can "spy" what the user is typing). Is pretty hard though to do in VB.
Hope this helps.
It basically means intercept window messages before they reach the target. For instance, you can subclass your form, which means that the function you created to handle the windows messages (your window proc, or subclass proc), receives the messages send to your window. Note that *all* messages are send to that function. You decide which messages you want to catch (for instance the WM_ACTIVATE, which are send both when you're app gets the focus, as when it looses the focus). Depending on the message, you do something and send it to the original window proc, or not (which can cause funny things ;-).
The kewl thing of this is that you can either get events which you wont get otherwise (WM_ACTIVATE doesn't have a VB-event), or you can make things go smoother (for instance, if you want your app to be not be able to be resized smaller then a certain size, you can do it in the form_resize event, but that looks ugly. If you subclass the form, you handle the message before VB raises the resize event, and then you can make it look kewl (if you have VB running in the SDI mode, the main VB window cannot be resized smaller then it's initial height, that's what you can do with subclassing). Or you can do kewl things like drawing your custom form caption.
I talk about a form here, but it counts for *every* object which has a hWnd property (you can subclass a textbox to remove the right mouse menu, or to make sure you can't paste in the textbox).
A hook is, from what I've seen, used in "keyboard hook", which is intercepting the keyboard events before the active application receives them (so you can "spy" what the user is typing). Is pretty hard though to do in VB.
Hope this helps.