CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Dec 1999
    Location
    Dublin, Ireland
    Posts
    1,173

    How to know if my class is declared "WithEvents"?

    I have written a class, ApiWindow that extends the Visual Basic form by adding a bunch of properties and events.

    The events are triggered by subclassing the form and raising them according to the windows messages recieved by the window. However it is wasteful to subclass a window for an instance of the class that has been created without the WithEvents keyword.

    Is there any way to know (from within my ApiWindow class) whether or not it has been declared WithEvents?

    Any help appreciated...

    -------------------------------------------------
    Ex. Datis: Duncan Jones
    Merrion Computing Ltd
    http://www.merrioncomputing.com
    Check out the new downloads - ImageMap.ocx is the VB control that emulates an HTML image map, EventVB.OCX for adding new events to your VB form and adding System Tray support simply, MCL Hotkey for implemenmting system-wide hotkeys in your application...all with source code included.
    '--8<-----------------------------------------
    NEW -The printer usage monitoring application
    '--8<------------------------------------------

  2. #2
    Join Date
    May 1999
    Location
    Omika, Japan
    Posts
    729

    Re: How to know if my class is declared "WithEvents"?

    If you are interesed in the solution only!, a round about way may be used. This class will have a public function using which some internal variable can be set to true; And when this variable is true, you subclass & raise events.
    And default value can be false.

    So for the (class's) clients, those interested in the events should, apart from declaring the instance WithEvents should also make sure that they set the "RingMeBack" to True after class instantiation.


    RK

  3. #3
    Join Date
    Dec 1999
    Location
    Dublin, Ireland
    Posts
    1,173

    Re: How to know if my class is declared "WithEvents"?

    That is effectively what I have at the moment...I was just thinking it might be nicer to take that step away from the programmer as it could be easy to miss.

    -------------------------------------------------
    Ex. Datis: Duncan Jones
    Merrion Computing Ltd
    http://www.merrioncomputing.com
    Check out the new downloads - ImageMap.ocx is the VB control that emulates an HTML image map, EventVB.OCX for adding new events to your VB form and adding System Tray support simply, MCL Hotkey for implemenmting system-wide hotkeys in your application...all with source code included.
    '--8<-----------------------------------------
    NEW -The printer usage monitoring application
    '--8<------------------------------------------

  4. #4
    Join Date
    Jun 2001
    Location
    MO, USA
    Posts
    2,868

    Re: How to know if my class is declared "WithEvents"?

    Another approach on this... obviously at design time, the VB editor knows that there are events (because they show up in the dropdown list). If you can figure out how it is determining this, perhaps you could write a value to the propertybag for your class. Just a thought....


  5. #5
    Join Date
    Jun 2001
    Location
    MO, USA
    Posts
    2,868

    Re: How to know if my class is declared "WithEvents"?

    I'm may have stumbled upon something which may help you with this, I haven't studied it enought to know for sure, but add a reference to "Typelib Information" (TLBINF32.DLL) and look at it in the object browser... interesting stuff if you can figure it all out!


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

Featured