Solved

Subclassing an ActiveX control

Posted on 1998-02-28
8
465 Views
Last Modified: 2013-11-20
I know how to subclass a commmon windows control when creating an MFC ActiveX Control (just select from the list box).  But I would like to do the same type of thing with an existing ActiveX control, basically I want to take an existing ActiveX and and some additional functionality.  I am trying to meet a deadline, so if someone could just paste some quick and dirty instructions, and I'll worry about understanding what I did later.  Thanks,
0
Comment
Question by:willman
  • 3
  • 3
  • 2
8 Comments
 
LVL 32

Expert Comment

by:jhance
ID: 1316659
ActiveX control are not like Windows controls.  ActiveX controls are managed by the COM subsystem in Windows.  It is possible to "subclass" them but the technique is very different than how you do it for common controls.  You need to make a new ActiveX control that with both contain your old control and expose a new interface that will "plug" into your existing application.  The containing control will thus be in the middle between your app and the old control.  Any messages that can be processed the old way can just be passed on to the old control.  Any extensions should be handled by your new control.  
0
 
LVL 2

Author Comment

by:willman
ID: 1316660
I had assumed it would be "very different".  This seems a very vague and undetailed answer for a 220 point question.
0
 
LVL 32

Expert Comment

by:jhance
ID: 1316661
How familiar you are with ActiveX control development?  Do you know how to build a control or are you just familiar with using controls in your application?
0
 
LVL 11

Expert Comment

by:mikeblas
ID: 1316662
But, the problem is that you can't do "the same type of thing".  OLE Controls simply don't provide a mechanism to sublcass eachother.

The two things you can do are:

1) Write a new control that contains the other control. Then, it's up to you to expose whatever interface from your control that you want to expose.  You'll need to recreate the methods want to expose, and you can do whatever you'd like to them as they go by before you call the method on the control your containing. Same thing for events fired from the control you're containing. You'll have some funky focus and input problems, depending on how complicated the control you're containing is. The issues that you'll face are largely solved by the http://support.microsoft.com/support/kb/articles/q155/9/73.asp KB article--containing a dialog in an OLE control causes the same problems you'll face.

2) You can take a strictly OLE approach and aggregate on the control. That'll work, but MFC provides very little support for writing the aggregating control. (Any MFC control can be aggregated.) This approach can relieve the issues you'll face above, but is a much more difficult approach as you'll need to use ATL or COM directly to implement your aggregation wrapper.

None of these things is close to the "same type of thing" as subclassing. They're very, very different. "Just adding some functionality" might be trivial, if you're just going to add a few extra properties, fluff up a couple of methods into more functionality.

On the other hand, if you need to fire some extra events, you're probably going to face a very difficult road. If you're going to try to do some different or alternate rendering within the control, you're in big big trouble.

.B ekiM

0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 2

Author Comment

by:willman
ID: 1316663
Thanks Mikeblas,  I not familiar with aggregating--if you could give me some more info, I'd appreciate it.

to jhance: I have written a few small controls in VC++, and have written one in VB5 (Though VB hardly counts), so I have some experience in creating, but not alot.

The reason I am doing this "upgrading" of a control, Is that I am going to use it on a web page, but certain elements of the control can only be changed when it is created with the CWnd::Create or CWnd::CreateEx functions -- functions I obviously would not have access to in a web page, even with the best scripting language.  Although the control is fairly complicated, it looks as if mikeblas option #1 will be the most feasible.
0
 
LVL 11

Expert Comment

by:mikeblas
ID: 1316664
The docs cover aggregation better than I can, here.  The bottom line is that you have two objects: one you write, and one you're containing.  You supply your own IUnknown implementation that provides pointers to interfaces that you implemnet yourself, _or_ to interfaces actually exposed by the object you're containing. It's up to you, and the decision of which interface to supply ends up being very similar to the way you decide which virtuals to override in regular C++.

.B ekiM
0
 
LVL 11

Accepted Solution

by:
mikeblas earned 220 total points
ID: 1316665
Do you need anything else?

.B ekiM

0
 
LVL 2

Author Comment

by:willman
ID: 1316666
Thanks, aggregation was what I was looking for -- It's only slightly more difficult than inheriting a C++ class.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
MFC Dialog 9 47
iSeries FTP Exit Program 8 114
Host to IP 7 73
either24  challenge 19 84
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
The purpose of this video is to demonstrate how to set up the WordPress backend so that each page automatically generates a Mailchimp signup form in the sidebar. This will be demonstrated using a Windows 8 PC. Tools Used are Photoshop, Awesome…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now