1 \section{\class{wxAutomationObject
}}\label{wxautomationobject
}
3 The
{\bf wxAutomationObject
} class represents an OLE automation object containing a single data member,
4 an IDispatch pointer. It contains a number of functions that make it easy to perform
5 automation operations, and set and get properties. The class makes heavy use of the
\helpref{wxVariant
}{wxvariant
} class.
7 The usage of these classes is quite close to OLE automation usage in Visual Basic. The API is
8 high-level, and the application can specify multiple properties in a single string. The following example
9 gets the current Excel instance, and if it exists, makes the active cell bold.
13 wxAutomationObject excelObject;
14 if (excelObject.GetInstance("Excel.Application"))
15 excelObject.PutProperty("ActiveCell.Font.Bold", true);
19 Note that this class obviously works under Windows only.
21 \wxheading{Derived from
}
23 \helpref{wxObject
}{wxobject
}
25 \wxheading{Include files
}
27 <wx/msw/ole/automtn.h>
31 \helpref{wxCore
}{librarieslist
}
35 \helpref{wxVariant
}{wxvariant
}
37 \latexignore{\rtfignore{\wxheading{Members
}}}
39 \membersection{wxAutomationObject::wxAutomationObject
}\label{wxautomationobjectctor
}
41 \func{}{wxAutomationObject
}{\param{WXIDISPATCH*
}{ dispatchPtr = NULL
}}
43 Constructor, taking an optional IDispatch pointer which will be released when the
46 \membersection{wxAutomationObject::
\destruct{wxAutomationObject
}}\label{wxautomationobjectdtor
}
48 \func{}{\destruct{wxAutomationObject
}}{\void}
50 Destructor. If the internal IDispatch pointer is non-null, it will be released.
52 \membersection{wxAutomationObject::CallMethod
}\label{wxautomationobjectcallmethod
}
54 \constfunc{wxVariant
}{CallMethod
}{\param{const wxString\&
}{ method
},
\param{int
}{ noArgs
},
55 \param{wxVariant
}{args
[]}}
57 \constfunc{wxVariant
}{CallMethod
}{\param{const wxString\&
}{ method
},
\param{...
}{}}
59 Calls an automation method for this object. The first form takes a method name, number of
60 arguments, and an array of variants. The second form takes a method name and zero to six
61 constant references to variants. Since the variant class has constructors for the basic
62 data types, and C++ provides temporary objects automatically, both of the following lines
63 are syntactically valid:
67 wxVariant res = obj.CallMethod("Sum", wxVariant(
1.2), wxVariant(
3.4));
68 wxVariant res = obj.CallMethod("Sum",
1.2,
3.4);
72 Note that
{\it method
} can contain dot-separated property names, to save the application
73 needing to call GetProperty several times using several temporary objects. For example:
77 object.CallMethod("ActiveCell.Font.ShowDialog", "My caption");
81 \membersection{wxAutomationObject::CreateInstance
}\label{wxautomationobjectcreateinstance
}
83 \constfunc{bool
}{CreateInstance
}{\param{const wxString\&
}{ classId
}}
85 Creates a new object based on the class id, returning true if the object was successfully created,
88 \membersection{wxAutomationObject::GetDispatchPtr
}\label{wxautomationobjectgetdispatchptr
}
90 \constfunc{IDispatch*
}{GetDispatchPtr
}{\void}
92 Gets the IDispatch pointer.
94 \membersection{wxAutomationObject::GetInstance
}\label{wxautomationobjectgetinstance
}
96 \constfunc{bool
}{GetInstance
}{\param{const wxString\&
}{ classId
}}
98 Retrieves the current object associated with a class id, and attaches the IDispatch pointer
99 to this object. Returns true if a pointer was successfully retrieved, false otherwise.
101 Note that this cannot cope with two instances of a given OLE object being active simultaneously,
102 such as two copies of Excel running. Which object is referenced cannot currently be specified.
104 \membersection{wxAutomationObject::GetObject
}\label{wxautomationobjectgetobject
}
106 \constfunc{bool
}{GetObject
}{\param{wxAutomationObject\&
}{obj
},
\param{const wxString\&
}{ property
},
107 \param{int
}{ noArgs =
0},
\param{wxVariant
}{args
[] = NULL
}}
109 Retrieves a property from this object, assumed to be a dispatch pointer, and initialises
{\it obj
} with it.
110 To avoid having to deal with IDispatch pointers directly, use this function in preference
111 to
\helpref{wxAutomationObject::GetProperty
}{wxautomationobjectgetproperty
} when retrieving objects
114 Note that an IDispatch pointer is stored as a void* pointer in wxVariant objects.
118 \helpref{wxAutomationObject::GetProperty
}{wxautomationobjectgetproperty
}
120 \membersection{wxAutomationObject::GetProperty
}\label{wxautomationobjectgetproperty
}
122 \constfunc{wxVariant
}{GetProperty
}{\param{const wxString\&
}{ property
},
\param{int
}{ noArgs
},
123 \param{wxVariant
}{args
[]}}
125 \constfunc{wxVariant
}{GetProperty
}{\param{const wxString\&
}{ property
},
\param{...
}{}}
127 Gets a property value from this object. The first form takes a property name, number of
128 arguments, and an array of variants. The second form takes a property name and zero to six
129 constant references to variants. Since the variant class has constructors for the basic
130 data types, and C++ provides temporary objects automatically, both of the following lines
131 are syntactically valid:
135 wxVariant res = obj.GetProperty("Range", wxVariant("A1"));
136 wxVariant res = obj.GetProperty("Range", "A1");
140 Note that
{\it property
} can contain dot-separated property names, to save the application
141 needing to call GetProperty several times using several temporary objects.
143 \membersection{wxAutomationObject::Invoke
}\label{wxautomationobjectinvoke
}
145 \constfunc{bool
}{Invoke
}{\param{const wxString\&
}{ member
},
\param{int
}{ action
},
146 \param{wxVariant\&
}{retValue
},
\param{int
}{ noArgs
},
\param{wxVariant
}{ args
[]},
147 \param{const wxVariant*
}{ ptrArgs
[] =
0}}
149 This function is a low-level implementation that allows access to the IDispatch Invoke function.
150 It is not meant to be called directly by the application, but is used by other convenience functions.
152 \wxheading{Parameters
}
154 \docparam{member
}{The member function or property name.
}
156 \docparam{action
}{Bitlist: may contain DISPATCH
\_PROPERTYPUT, DISPATCH
\_PROPERTYPUTREF,
159 \docparam{retValue
}{Return value (ignored if there is no return value)
}.
161 \docparam{noArgs
}{Number of arguments in
{\it args
} or
{\it ptrArgs
}.
}
163 \docparam{args
}{If non-null, contains an array of variants.
}
165 \docparam{ptrArgs
}{If non-null, contains an array of constant pointers to variants.
}
167 \wxheading{Return value
}
169 true if the operation was successful, false otherwise.
173 Two types of argument array are provided, so that when possible pointers are used for efficiency.
175 \membersection{wxAutomationObject::PutProperty
}\label{wxautomationobjectputproperty
}
177 \constfunc{bool
}{PutProperty
}{\param{const wxString\&
}{ property
},
\param{int
}{ noArgs
},
178 \param{wxVariant
}{args
[]}}
180 \func{bool
}{PutProperty
}{\param{const wxString\&
}{ property
},
\param{...
}{}}
182 Puts a property value into this object. The first form takes a property name, number of
183 arguments, and an array of variants. The second form takes a property name and zero to six
184 constant references to variants. Since the variant class has constructors for the basic
185 data types, and C++ provides temporary objects automatically, both of the following lines
186 are syntactically valid:
190 obj.PutProperty("Value", wxVariant(
23));
191 obj.PutProperty("Value",
23);
195 Note that
{\it property
} can contain dot-separated property names, to save the application
196 needing to call GetProperty several times using several temporary objects.
198 \membersection{wxAutomationObject::SetDispatchPtr
}\label{wxautomationobjectsetdispatchptr
}
200 \func{void
}{SetDispatchPtr
}{\param{WXIDISPATCH*
}{ dispatchPtr
}}
202 Sets the IDispatch pointer. This function does not check if there is already an IDispatch pointer.
204 You may need to cast from IDispatch* to WXIDISPATCH* when calling this function.