1 /////////////////////////////////////////////////////////////////////////////
2 // Name: msw/ole/automtn.h
3 // Purpose: interface of wxAutomationObject
4 // Author: wxWidgets team
6 // Licence: wxWindows licence
7 /////////////////////////////////////////////////////////////////////////////
10 Automation object creation flags.
12 These flags can be used with wxAutomationObject::GetInstance().
16 enum wxAutomationInstanceFlags
19 Only use the existing instance, never create a new one.
21 This flag can be used to forbid the creation of a new instance if none
24 wxAutomationInstance_UseExistingOnly
= 0,
27 Create a new instance if there are no existing ones.
29 This flag corresponds to the default behaviour of
30 wxAutomationObject::GetInstance() and means that if getting an existing
31 instance failed, we should call wxAutomationObject::CreateInstance() to
34 wxAutomationInstance_CreateIfNeeded
= 1,
37 Do not show an error message if no existing instance is currently
40 All other errors will still be reported as usual.
42 wxAutomationInstance_SilentIfNone
= 2
47 @class wxAutomationObject
49 The @b wxAutomationObject class represents an OLE automation object containing
51 an IDispatch pointer. It contains a number of functions that make it easy to
53 automation operations, and set and get properties. The class makes heavy use of
56 The usage of these classes is quite close to OLE automation usage in Visual
58 high-level, and the application can specify multiple properties in a single
59 string. The following example
60 gets the current Excel instance, and if it exists, makes the active cell bold.
63 wxAutomationObject excelObject;
64 if (excelObject.GetInstance("Excel.Application"))
65 excelObject.PutProperty("ActiveCell.Font.Bold", @true);
68 Note that this class obviously works under Windows only.
77 class wxAutomationObject
: public wxObject
81 Constructor, taking an optional IDispatch pointer which will be released when
85 wxAutomationObject(WXIDISPATCH
* dispatchPtr
= NULL
);
88 Destructor. If the internal IDispatch pointer is non-null, it will be released.
90 ~wxAutomationObject();
94 Calls an automation method for this object. The first form takes a method name,
96 arguments, and an array of variants. The second form takes a method name and
98 constant references to variants. Since the variant class has constructors for
100 data types, and C++ provides temporary objects automatically, both of the
102 are syntactically valid:
104 Note that @a method can contain dot-separated property names, to save the
106 needing to call GetProperty several times using several temporary objects. For
109 wxVariant
CallMethod(const wxString
& method
, int noArgs
,
110 wxVariant args
[]) const;
111 const wxVariant
CallMethod(const wxString
& method
, ... ) const;
115 Creates a new object based on the ProgID, returning @true if the object was
116 successfully created,
119 bool CreateInstance(const wxString
& progId
) const;
122 Checks if the object is in a valid state.
124 Returns @true if the object was successfully initialized or @false if
125 it has no valid IDispatch pointer.
127 @see GetDispatchPtr()
132 Gets the IDispatch pointer.
134 Notice that the return value of this function is an untyped pointer but
135 it can be safely cast to @c IDispatch.
137 void* GetDispatchPtr() const;
140 Retrieves the current object associated with the specified ProgID, and
141 attaches the IDispatch pointer to this object.
143 If attaching to an existing object failed and @a flags includes
144 wxAutomationInstance_CreateIfNeeded flag, a new object will be created.
145 Otherwise this function will normally log an error message which may be
146 undesirable if the object may or may not exist. The
147 wxAutomationInstance_SilentIfNone flag can be used to prevent the error
148 from being logged in this case.
150 Returns @true if a pointer was successfully retrieved, @false
153 Note that this cannot cope with two instances of a given OLE object being
154 active simultaneously,
155 such as two copies of Excel running. Which object is referenced cannot
156 currently be specified.
158 @param progId COM ProgID, e.g. "Excel.Application"
159 @param flags The creation flags (this parameters was added in wxWidgets
162 bool GetInstance(const wxString
& progId
,
163 int flags
= wxAutomationInstance_CreateIfNeeded
) const;
166 Retrieves a property from this object, assumed to be a dispatch pointer, and
167 initialises @a obj with it.
168 To avoid having to deal with IDispatch pointers directly, use this function in
170 to GetProperty() when retrieving objects
172 Note that an IDispatch pointer is stored as a void* pointer in wxVariant
177 bool GetObject(wxAutomationObject
& obj
, const wxString
& property
,
179 wxVariant args
[] = NULL
) const;
183 Gets a property value from this object. The first form takes a property name,
185 arguments, and an array of variants. The second form takes a property name and
187 constant references to variants. Since the variant class has constructors for
189 data types, and C++ provides temporary objects automatically, both of the
191 are syntactically valid:
193 Note that @a property can contain dot-separated property names, to save the
195 needing to call GetProperty several times using several temporary objects.
197 wxVariant
GetProperty(const wxString
& property
, int noArgs
,
198 wxVariant args
[]) const;
199 const wxVariant
GetProperty(const wxString
& property
, ... ) const;
203 This function is a low-level implementation that allows access to the IDispatch
205 It is not meant to be called directly by the application, but is used by other
206 convenience functions.
209 The member function or property name.
211 Bitlist: may contain DISPATCH_PROPERTYPUT, DISPATCH_PROPERTYPUTREF,
214 Return value (ignored if there is no return value)
216 Number of arguments in args or ptrArgs.
218 If non-null, contains an array of variants.
220 If non-null, contains an array of constant pointers to variants.
222 @return @true if the operation was successful, @false otherwise.
224 @remarks Two types of argument array are provided, so that when possible
225 pointers are used for efficiency.
227 bool Invoke(const wxString
& member
, int action
,
228 wxVariant
& retValue
, int noArgs
,
230 const wxVariant
* ptrArgs
[] = 0) const;
234 Puts a property value into this object. The first form takes a property name,
236 arguments, and an array of variants. The second form takes a property name and
238 constant references to variants. Since the variant class has constructors for
240 data types, and C++ provides temporary objects automatically, both of the
242 are syntactically valid:
244 Note that @a property can contain dot-separated property names, to save the
246 needing to call GetProperty several times using several temporary objects.
248 bool PutProperty(const wxString
& property
, int noArgs
,
250 const bool PutProperty(const wxString
& property
, ... );
254 Sets the IDispatch pointer. This function does not check if there is already an
256 You may need to cast from IDispatch* to WXIDISPATCH* when calling this function.
258 void SetDispatchPtr(WXIDISPATCH
* dispatchPtr
);