dcsimg
Results 1 to 5 of 5

Thread: [vbRichClient5] Subclass Wrapper supporting multiple hWnds & Before/After events

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2010
    Location
    Canada
    Posts
    1,323

    [vbRichClient5] Subclass Wrapper supporting multiple hWnds & Before/After events

    This project wraps the vbRichClient5 CSubclass class, adding support for multiple hWnds and Before/After events.

    I wanted to replace some old thunky subclassing code I was using that was occasionally giving me "weird" errors after extended use. I figured the RC5 CSubclass would be a good place to start since I already use the library, but I found it to be a bit "spare" as you can only subclass a single hWnd and you have to handle before/after original wndproc handling manually for each case.

    In hopes of developing something that would be close(r) to a drop-in replacement for the old code, I decided to build a small wrapper around the RC5 CSubclass class.

    Usage is pretty simple. Call Subclass and pass an hWnd and optional UserParameter (Long) to set up a window for subclassing. Next, call AddMessage for any Windows message # that you want to intercept. You can set whether or not to activate the Before and After events for each message in the AddMessage call.

    Before events are fired before the original wndproc is called, and you can set the p_Handled parameter to True to skip the original wndproc, thus overriding default behaviour of the message.

    After events are fired after the original wndproc is called, so they are useful for reacting to stuff that happens after the default behaviour of the message. NOTE: After events will not fire if you previously set p_Handled = True in a corresponding Before event for a given message.

    There's a small demonstration project that prevents characters 0-9 from being typed into TextBoxes.

    That's about it, nothing ground-breaking here. Hope someone finds it useful!

    IMPORTANT BUGFIX 2019-08-21 - Fixed bad key in CallOriginalWindowProcedure method.

    Latest Version: RC5SubclassWrapper.zip
    Last edited by jpbro; Aug 21st, 2019 at 09:10 AM. Reason: Bug Fix

  2. #2
    Frenzied Member
    Join Date
    Apr 2012
    Posts
    1,098

    Re: [vbRichClient5] Subclass Wrapper supporting multiple hWnds & Before/After events

    Thanks for sharing
    If you don't know where you're going, any road will take you there...

    My VB6 love-children: Vee-Hive and Vee-Launcher

  3. #3
    New Member
    Join Date
    Feb 2016
    Posts
    4

    Re: [vbRichClient5] Subclass Wrapper supporting multiple hWnds & Before/After events

    That's very cool and helpful!

  4. #4
    Frenzied Member
    Join Date
    Sep 2012
    Posts
    1,598

    Re: [vbRichClient5] Subclass Wrapper supporting multiple hWnds & Before/After events

    Great ! Thank you, jpbro.

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2010
    Location
    Canada
    Posts
    1,323

    Re: [vbRichClient5] Subclass Wrapper supporting multiple hWnds & Before/After events

    Thanks for the thanks everyone

    In case any of you are using/testing it, I've just release an important bugfix/update. I was building a bad key in the CallOriginalWindowProcedure method, which would raise an error and fail to call the original window procedure. I almost always use a single key building function for stuff like this for this exact reason, but apparently I got lazy this time Anyway, that's rectified in the latest version available in the first post.

    Also added a bit of licensing & warrant info to the source. The code is Public Domain and usable for any purpose you like with no attribution required. There is absolutely no warranty, so use at your own risk.

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width