]>
git.saurik.com Git - wxWidgets.git/blob - interface/wx/msw/ole/automtn.h
397703cbe8cb18e5c75e04aadf38e9eff064736f
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: msw/ole/automtn.h
3 // Purpose: interface of wxAutomationObject
4 // Author: wxWidgets team
6 // Licence: wxWindows licence
7 /////////////////////////////////////////////////////////////////////////////
10 @class wxAutomationObject
12 The @b wxAutomationObject class represents an OLE automation object containing
14 an IDispatch pointer. It contains a number of functions that make it easy to
16 automation operations, and set and get properties. The class makes heavy use of
19 The usage of these classes is quite close to OLE automation usage in Visual
21 high-level, and the application can specify multiple properties in a single
22 string. The following example
23 gets the current Excel instance, and if it exists, makes the active cell bold.
26 wxAutomationObject excelObject;
27 if (excelObject.GetInstance("Excel.Application"))
28 excelObject.PutProperty("ActiveCell.Font.Bold", @true);
31 Note that this class obviously works under Windows only.
40 class wxAutomationObject
: public wxObject
44 Constructor, taking an optional IDispatch pointer which will be released when
48 wxAutomationObject(WXIDISPATCH
* dispatchPtr
= NULL
);
51 Destructor. If the internal IDispatch pointer is non-null, it will be released.
53 ~wxAutomationObject();
57 Calls an automation method for this object. The first form takes a method name,
59 arguments, and an array of variants. The second form takes a method name and
61 constant references to variants. Since the variant class has constructors for
63 data types, and C++ provides temporary objects automatically, both of the
65 are syntactically valid:
67 Note that @a method can contain dot-separated property names, to save the
69 needing to call GetProperty several times using several temporary objects. For
72 wxVariant
CallMethod(const wxString
& method
, int noArgs
,
73 wxVariant args
[]) const;
74 const wxVariant
CallMethod(const wxString
& method
, ... ) const;
78 Creates a new object based on the ProgID, returning @true if the object was
82 bool CreateInstance(const wxString
& progId
) const;
85 Checks if the object is in a valid state.
87 Returns @true if the object was successfully initialized or @false if
88 it has no valid IDispatch pointer.
95 Gets the IDispatch pointer.
97 Notice that the return value of this function is an untyped pointer but
98 it can be safely cast to @c IDispatch.
100 void* GetDispatchPtr() const;
103 Retrieves the current object associated with the specified ProgID, and
104 attaches the IDispatch pointer to this object.
106 Returns @true if a pointer was successfully retrieved, @false
108 Note that this cannot cope with two instances of a given OLE object being
109 active simultaneously,
110 such as two copies of Excel running. Which object is referenced cannot
111 currently be specified.
113 bool GetInstance(const wxString
& progId
) const;
116 Retrieves a property from this object, assumed to be a dispatch pointer, and
117 initialises @a obj with it.
118 To avoid having to deal with IDispatch pointers directly, use this function in
120 to GetProperty() when retrieving objects
122 Note that an IDispatch pointer is stored as a void* pointer in wxVariant
127 bool GetObject(wxAutomationObject
& obj
, const wxString
& property
,
129 wxVariant args
[] = NULL
) const;
133 Gets a property value from this object. The first form takes a property name,
135 arguments, and an array of variants. The second form takes a property name and
137 constant references to variants. Since the variant class has constructors for
139 data types, and C++ provides temporary objects automatically, both of the
141 are syntactically valid:
143 Note that @a property can contain dot-separated property names, to save the
145 needing to call GetProperty several times using several temporary objects.
147 wxVariant
GetProperty(const wxString
& property
, int noArgs
,
148 wxVariant args
[]) const;
149 const wxVariant
GetProperty(const wxString
& property
, ... ) const;
153 This function is a low-level implementation that allows access to the IDispatch
155 It is not meant to be called directly by the application, but is used by other
156 convenience functions.
159 The member function or property name.
161 Bitlist: may contain DISPATCH_PROPERTYPUT, DISPATCH_PROPERTYPUTREF,
164 Return value (ignored if there is no return value)
166 Number of arguments in args or ptrArgs.
168 If non-null, contains an array of variants.
170 If non-null, contains an array of constant pointers to variants.
172 @return @true if the operation was successful, @false otherwise.
174 @remarks Two types of argument array are provided, so that when possible
175 pointers are used for efficiency.
177 bool Invoke(const wxString
& member
, int action
,
178 wxVariant
& retValue
, int noArgs
,
180 const wxVariant
* ptrArgs
[] = 0) const;
184 Puts a property value into this object. The first form takes a property name,
186 arguments, and an array of variants. The second form takes a property name and
188 constant references to variants. Since the variant class has constructors for
190 data types, and C++ provides temporary objects automatically, both of the
192 are syntactically valid:
194 Note that @a property can contain dot-separated property names, to save the
196 needing to call GetProperty several times using several temporary objects.
198 bool PutProperty(const wxString
& property
, int noArgs
,
200 const bool PutProperty(const wxString
& property
, ... );
204 Sets the IDispatch pointer. This function does not check if there is already an
206 You may need to cast from IDispatch* to WXIDISPATCH* when calling this function.
208 void SetDispatchPtr(WXIDISPATCH
* dispatchPtr
);