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

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


OCX nested objects

Alistair Israel -- aisrael@hotmail.com
Wednesday, July 24, 1996

Environment: MSVC++ 4.1, Win95

I'm using an OLE Control in an SDI app.  This I have accomplished by creating
the CWnd-based IDispatch wrapper class generated by MSVC
as a child window of my view class.  I have no problems manipulating
the control's basic properties and calling its methods (it's actually a control
that draws a graph).

My problem lies in how to fine-tune the layout of the control.  Unfortunately,
it doesn't implement all its layout 'properties' as simple properties
accessible through the wrapper, but as 'objects'.  I'm not sure whether this
means that they're actually nested OLE objects or just objects, as the
documentation doesn't really discuss the issue.

The provided sample code shows how to work with these 'object' properties in
VB, for example:

  MyChart.Grid.Pen.Width = 1

However, since I am using MSVC, I can't see how to get to the grid object to
get to the pen object to get to its width property.  I've searched the online
docs that came with the control, with MSVC (lots of docs on writing OCXes but
not much on _using_ them), and the MFC-l history at MFCPro.  Finally I decided
this might be a valid question for the MFC mailing list.

How do I get to these 'object properties' within the OCX in the simplest way
possible under MSVC?

My suspicions were actually aroused by a 'GetGrid()' method in the wrapper
class that returns an LPDISPATCH.  Does this mean that I have to get down &
dirty using the COleDispatchDriver class on my own?

Or is there a way to have MSVC generate wrapper classes for these
'objects' as well?


Hoping for the best,

/******************************
* Alistair Israel             *
* (aisrael@hotmail.com)       *
* Pilipino Data Network, Inc. *
* http://202.47.133.168       *
******************************/


---------------------------------------------------------
Get Your *Web-Based* Free Email at http://www.hotmail.com
---------------------------------------------------------



Mike Blaszczak -- mikeblas@msn.com
Saturday, July 27, 1996

OLE likes you to understand a heirarchical arrangement for objects between the 
dots.  It's really that simple, but if you still don't get it, read on:

If you have the statement

  MyChart.Grid.Pen.Width = 1

you're saying that "I have an object [of some well-known type] called MyChart, 
which has inside of it the interface Grid, which has inside of it the 
interface Pen, which has the property Width.  I want to assign an integer one 
to Width."

While it's convenient to use this in languages like Visual Basic, it isn't so 
easy to use in Visual C++.  It's not that hard, though: you already have a 
pointer to the IUnknown interface for your MyChart object.  You can call 
QueryInterface() of that IUnknown interface on MyChart to get the Grid 
interface.  That'll get you another IUnknown interface.  On that one, 
QueryInterface for the Pen interface.  Given that interface, you should be 
able to set the Width property.

Most complicated servers implement hierarchies like this: Excel, for example, 
has lots and lots of subobjects.  My book includes code that shows you how to 
do this navigation from the Excel application object itself into a particular 
instance of a chart down to some attributes of the chart. You can use very 
very similar code against your control instance.

QueryInterface(), of course, works by looking for interface IDs, or IIDs.  The 
IIDs may be available to you from any of a few different sources: a header 
file that defines preprocessor symbols you can use or that are identified as 
external symbols you can link to from a library, or by dynamically querying 
the type library of the object.

.B ekiM
http://www.nwlink.com/~mikeblas/
----------
From: 	owner-mfc-l@netcom.com on behalf of Alistair Israel
Sent: 	Wednesday, July 24, 1996 12:09 AM
To: 	mfc-l@netcom.com
Subject: 	OCX nested objects

Environment: MSVC++ 4.1, Win95

I'm using an OLE Control in an SDI app.  This I have accomplished by creating
the CWnd-based IDispatch wrapper class generated by MSVC
as a child window of my view class.  I have no problems manipulating
the control's basic properties and calling its methods (it's actually a 
control
that draws a graph).

My problem lies in how to fine-tune the layout of the control.  Unfortunately,
it doesn't implement all its layout 'properties' as simple properties
accessible through the wrapper, but as 'objects'.  I'm not sure whether this
means that they're actually nested OLE objects or just objects, as the
documentation doesn't really discuss the issue.

The provided sample code shows how to work with these 'object' properties in
VB, for example:

  MyChart.Grid.Pen.Width = 1

However, since I am using MSVC, I can't see how to get to the grid object to
get to the pen object to get to its width property.  I've searched the online
docs that came with the control, with MSVC (lots of docs on writing OCXes but
not much on _using_ them), and the MFC-l history at MFCPro.  Finally I decided
this might be a valid question for the MFC mailing list.

How do I get to these 'object properties' within the OCX in the simplest way
possible under MSVC?

My suspicions were actually aroused by a 'GetGrid()' method in the wrapper
class that returns an LPDISPATCH.  Does this mean that I have to get down &
dirty using the COleDispatchDriver class on my own?

Or is there a way to have MSVC generate wrapper classes for these
'objects' as well?


Hoping for the best,

/******************************
* Alistair Israel             *
* (aisrael@hotmail.com)       *
* Pilipino Data Network, Inc. *
* http://202.47.133.168       *
******************************/


---------------------------------------------------------
Get Your *Web-Based* Free Email at http://www.hotmail.com
---------------------------------------------------------




John & Annette Elsbree -- elsbree@msn.com
Monday, August 05, 1996

If the dispatch interfaces for Grid and Pen are described in the control's 
type library, then the Component Gallery should list these as classes it can 
generate when you try to import the control itself.

If these classes are in fact generated, you should be able to say something 
like this:

IGrid grid(ctl.GetGrid());
IPen pen(grid.GetPen());
int width = pen.GetWidth();

Of course, it would probably be wise to check for failure on the return values 
from GetGrid and GetPen.

If the grid and pen interfaces are not described in the type library, you'll 
probably need to contact the vendor from whom you obtained the control.

John

----------
From: 	owner-mfc-l@netcom.com on behalf of Alistair Israel
Sent: 	Wednesday, July 24, 1996 12:09 AM
To: 	mfc-l@netcom.com
Subject: 	OCX nested objects

Environment: MSVC++ 4.1, Win95

I'm using an OLE Control in an SDI app.  This I have accomplished by creating
the CWnd-based IDispatch wrapper class generated by MSVC
as a child window of my view class.  I have no problems manipulating
the control's basic properties and calling its methods (it's actually a 
control
that draws a graph).

My problem lies in how to fine-tune the layout of the control.  Unfortunately,
it doesn't implement all its layout 'properties' as simple properties
accessible through the wrapper, but as 'objects'.  I'm not sure whether this
means that they're actually nested OLE objects or just objects, as the
documentation doesn't really discuss the issue.

The provided sample code shows how to work with these 'object' properties in
VB, for example:

  MyChart.Grid.Pen.Width = 1

However, since I am using MSVC, I can't see how to get to the grid object to
get to the pen object to get to its width property.  I've searched the online
docs that came with the control, with MSVC (lots of docs on writing OCXes but
not much on _using_ them), and the MFC-l history at MFCPro.  Finally I decided
this might be a valid question for the MFC mailing list.

How do I get to these 'object properties' within the OCX in the simplest way
possible under MSVC?

My suspicions were actually aroused by a 'GetGrid()' method in the wrapper
class that returns an LPDISPATCH.  Does this mean that I have to get down &
dirty using the COleDispatchDriver class on my own?

Or is there a way to have MSVC generate wrapper classes for these
'objects' as well?


Hoping for the best,

/******************************
* Alistair Israel             *
* (aisrael@hotmail.com)       *
* Pilipino Data Network, Inc. *
* http://202.47.133.168       *
******************************/


---------------------------------------------------------
Get Your *Web-Based* Free Email at http://www.hotmail.com
---------------------------------------------------------





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