Subclassing and customizing OCXs in MFC
Fredrik Gunne -- fge@agema.se
Tuesday, July 02, 1996
Environment: VC4.1, Win NT 3.51
I have problems customizing the behaviour of an OCX. For instance, when
the OCX is used as an embedded object and is being saved, I want to save
other data than just properties (DoPropExchange).
The OCX contains an IMoniker interface, which needs an IStream interface
to be saved using OleSaveToStream. I have tried to override the
Serialize function, but at that point I only have a CArchive-ptr. So I
tried to implement my own IPersistStorage interface, but the original
MFC-interface keeps getting called.
I know there are ways to customize Ole objects using containment or
aggregation, but I was hoping there would be a nicer way using
C++-overriding etc.
Am I wrong?
Regards
Fredrik Gunne
John & Annette Elsbree -- elsbree@msn.com
Tuesday, July 09, 1996
Fredrik -
Before you try anything else, you should probably check whether PX_IUnknown
will do what you need. It generally works with any object that's compatible
with OleSaveToStream/OleLoadFromStream. This little helper might save you a
lot of work.
If that doesn't help, and you want to override Serialize (which I don't
recommend, for reasons I'll give momentarily), have a look at the
implementation of a function called _AfxGetArchiveStream in
mfc\src\ctlpropx.cpp. This shows one way of getting at the IStream in a
CArchive. This function isn't exported from the MFC DLLs, but you could easily
cut-n-paste it to your own code.
Keep in mind that when you override the Serialize method, your customizations
will ONLY work if the container saves your control using IPersistStorage or
IPersistStreamInit. If the container happens to use IPersistPropertyBag
instead, the Serialize function NEVER EVEN GETS CALLED. The most popular OLE
control container on the planet, Visual Basic, happens to save its controls in
this way.
For a fully general solution, you'll need to create a stream that operates on
a blob of memory, and use PX_Blob to load and save it.
John ("not speaking for Microsoft") Elsbree
----------
From: owner-mfc-l@netcom.com on behalf of Fredrik Gunne
Environment: VC4.1, Win NT 3.51
I have problems customizing the behaviour of an OCX. For instance, when
the OCX is used as an embedded object and is being saved, I want to save
other data than just properties (DoPropExchange).
The OCX contains an IMoniker interface, which needs an IStream interface
to be saved using OleSaveToStream. I have tried to override the
Serialize function, but at that point I only have a CArchive-ptr.
Fredrik Gunne
| Вернуться в корень Архива
|