15 мая 2023 года "Исходники.РУ" отмечают своё 23-летие!
Поздравляем всех причастных и неравнодушных с этим событием!
И огромное спасибо всем, кто был и остаётся с нами все эти годы!

Главная Форум Журнал Wiki DRKB Discuz!ML Помощь проекту


Nested OLE (ActvieX) Controls

Joseph Jones -- jjones@FrontofficeTech.com
Thursday, November 14, 1996

Environment: VC++ 4.2b (Enterprise Editioin), NT 4.0, Win95

I am trying to create an OLE control that embedds other OLE controls.
The
Documentation is a little sparse on this, and I was wondering if anyone
could provide some help (especially some sample code) that does this.
Note, not only do I need an OLE control that is itself a container, but
I
also need to know how to create an OLE control to place into that
container
programmatically.




Alan -- aduggan@dsc001.reo.dec.com
Monday, November 18, 1996

[Mini-digest: 2 responses]

Hi Joseph,

Environment : VC++ 4.2 Enterprise, NT4.0

We covered this ground some time back and found some useful help in a
book called OLE Controls Inside Out by Adam Denning from Microsoft
Press. It covers the idea of having multiple child windows within a
control, the example given has a button and an edit box.
You add two member variables, one for each child control, CEdit and
CButton, and a CRect for each to hold size and position.
We didn't pursue this further than using stock controls, so I would be
interested in your experiences if you venture further.

Regards,
Alan


Alan Duggan			DSC Ltd.
Senior Software Engineer	Galway Technology Centre
				Mervue
Tel:  +353 91 760541		Galway
Fax: +353 91 760542		Ireland
>
-----From: "Giles R. Chamberlin" 


> I am trying to create an OLE control that embedds other OLE controls.
Use the component gallery to add the ocx you wish to contain to your   
project.  This creates a class wrapper for the ocx's IDispatch.   
 Instantiate the embedded OCX by calling the class wrappers Create   
function, then call automation methods to your hearts delight.

Hooking events is a bit harder:
Events are handled by you providing an appropriate IDispatch interface to   
the OCX.  To achieve this:

1) Create an event handler.
Derive an Event Handler class from CCmdTarget with automation enabled.   
 This gives you an IDispatch derived interface.

Use ClassWizard to add Automation methods to your EventHandler.  Make   
sure they're added in the order that the
events are listed in the OCX.  ole2vw32.exe will be useful here.

Change your EventHandler interface IID to match the IID of the OCX's   
event interface.  ole2vw32 again.  Use "find in files" to make sure you   
get it all!  Be warned that it also appears in your odl file.

2) Now connect it up
Get the IUnknown of your OCX  (MFC GetControlUnknown)
QueryInterface for IID_IConnectionPointContainer
FindConnectionPoint for the IID of the OCX's events == IID of your event   
handler.
And then call Advise on IConnectionPoint with the IDispatch of your   
EventHandler (found using GetIDispatch);

On the way through the above, call Release on the interfaces as you   
finish with them and be sure to check return codes as you may get non   
NULL interface pointers returned by calls that have failed.  Use the   
macros FAILED() or SUCCEEDED() to check return codes.

3) Fire it all up and enjoy!

Good luck,

Giles Chamberlin,
Softwright.





| Вернуться в корень Архива |