Results 1 to 4 of 4

Thread: What is SubClassing?

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Oct 1999
    Location
    chennai,tamilnadu,india
    Posts
    29
    Hi all,

    Can any one let me know what is subclassing concept...
    If any sites on that it will be most welcomed..
    Thanx
    Regards
    Murali

  2. #2
    Frenzied Member
    Join Date
    Mar 2000
    Posts
    1,089
    Subclassing is a way of getting more events than vb fires, or changing those events before vb gets them. To do this you have to understand what goes on behind the scenes before an event is fired. Say the user clicks a button you've put on the form.

    The mouse sends a message to the mousedriver saying it's been clicked

    The mousedriver then sends a message to windows saying the mouse has been clicked,

    Windows decides which window has been clicked(in this case your command button, which like anything you can see on the screen is a window) and calls it's window procedure with information saying that the mouse has been clicked and where it is on the screen.

    VB sends a click event to your code.

    there's a few more steps in there probably some I don't know about as well but these are the important ones.

    when you subclass you tell windows that the default window procedure is your own procedure and not VB's window procedure, so Your code gets information about everything that happens to the window and can changeit before vb gets to it

    for example you could use subclassing to trap a click event on a picture before vb gets to it and check where it is on the picture then only send it if the click is on part of the picture you want and ignore it if it isnt.

    unfortunatly subclassing is very dangerous because vb isn't handling your errors for you so If you mke a mistake VB will crash and you'll loose all your saved information. That's happened to me 8 times today and I've only been up for 2 hours.

    Any Decent book on the API will explain subclassing or just check out the tips on this site and it's partners there's bound to be something there.

    Hope this helps

  3. #3
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744
    This is what MSDN has to say about subclassing:

    Subclassing Defined:
    Subclassing is a technique that allows an application to intercept messages destined for another window. An application can augment, monitor, or modify the default behavior of a window by intercepting messages meant for another window. Subclassing is an effective way to change or extend the behavior of a window without redeveloping the window. Subclassing the default control window classes (button controls, edit controls, list controls, combo box controls, static controls, and scroll bar controls) is a convenient way to obtain the functionality of the control and to modify its behavior. For example, if a multiline edit control is included in a dialog box and the user presses the ENTER key, the dialog box closes. By subclassing the edit control, an application can have the edit control insert a carriage return and line feed into the text without exiting the dialog box. An edit control does not have to be developed specifically for the needs of the application.

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Oct 1999
    Location
    chennai,tamilnadu,india
    Posts
    29
    Hi all,

    Thanx very much for your Explanations.

    Regards
    Murali

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width