Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Subclassing within activeX

Status
Not open for further replies.

john30120

Technical User
Dec 7, 2001
22
US
I am trying to do something in VB6 that perhaps would be better done in C++ (which I am trying to avoid due to incompetence).

I have a dll that interacts with the sound card and returns events through windows messages. To set up the subclass to intercept the messages I need to use the AddressOf operator which requires the function to be in a module. That function then calls other functions back on the form which is accessed by call form1.myProc(). This works fine in a regular VB EXE program.

But trying to do the same thing when making an activeX control is problematic. The control code on "UserControl1" can call subs in the module but I can't get the sub on the module (which must be there to get AddressOf to work) to return the call. Call UserControl1.myProc() doesn't work from the module.

Is there another way or is there some other construct needed to allow procedures in the module to call procedures in the ActiveX control or do modules have a limited role in activeX or possibly can the windows messaging scheme be handled differently within an ActiveX control?

Thanks



 
Perhaps I am misunderstanding you, but just like an ActiveX control that passes events (RaiseEvent) back to the owning form like the scroll_change event of a scroll bar... or am I off in left/LaLa field/land again?

Good Luck

 
The essence of the problem is this. In a regular VB EXE program you might have MyForm.bas and MyModule.mod and if you had a subroutine in MyModule.mod that needed to call a subroutine in MyForm.bas you could do so with the call call MyForm.mySub().

In the ActiveX world you have UserControl.ctl and MyModule.bas. If you have a subroutine on MyModule.bas that needs to call a subroutine (or address a Label) located on UserControl.ctl, how do you do that? Call UserControl.mySub() doesn't work from the module nor does UserControl.Label1.Caption = "XYZ".

Thanks
 
Okay, its been awhile since I have played around with control creation so I had to look this up in my Microsoft Programming Series, Programming Microsoft Visual Basic 6.0 by Francesco Balena and on pg.926 it states.

"An ActiveX Control can access other controls on its parent form in two distinct ways. The first approach is based on the controls collection of the parent object..."
[tt]
Dim ctrl As Object
For Each ctrl In Parent.Controls
If Not (ctrl Is Extender) Then
...
[/tt]
"The items in the Parent controls collection are all extender object, so if you want to sort out the ActiveX control that's running the code you must compare each item with the extender property, not with the me keyword. The problem with this approach is that it works only under vb (more precisely, only under environments for which there is a parent object the exposes the controls collections."

"The second approach is based on the parentcontrols property. Unlike the parent.controls collection, this property is guaranteed to work with all containers. The items in the parent.controls collection contain the parent form itself, but you can easily filter it out by comparing each reference withe the parent object (if there is one)."


So if that is not confusing enough for you let me explain what my first post meant...

just like creating a usercontrol that has events, why can you not create a class that you call from your mod that raises events and allow the user to select which events they want to recieve?

Then there is another method mentioned in the book but I'm done reading for now. It's early and I need some sleep!

Good Luck

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top