1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- /home/espenr/tmp/qt-3.3.8-espenr-2499/qt-x11-free-3.3.8/extensions/activeqt/examples/opengl/opengl.doc:33 -->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Qt' OpenGL widgets as an ActiveX (executable)</title>
<style type="text/css"><!--
fn { margin-left: 1cm; text-indent: -1cm; }
a:link { color: #004faf; text-decoration: none }
a:visited { color: #672967; text-decoration: none }
body { background: #ffffff; color: black; }
--></style>
</head>
<body>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr bgcolor="#E5E5E5">
<td valign=center>
<a href="index.html">
<font color="#004faf">Home</font></a>
| <a href="classes.html">
<font color="#004faf">All Classes</font></a>
| <a href="mainclasses.html">
<font color="#004faf">Main Classes</font></a>
| <a href="annotated.html">
<font color="#004faf">Annotated</font></a>
| <a href="groups.html">
<font color="#004faf">Grouped Classes</font></a>
| <a href="functions.html">
<font color="#004faf">Functions</font></a>
</td>
<td align="right" valign="center"><img src="logo32.png" align="right" width="64" height="32" border="0"></td></tr></table><h1 align=center>Qt' OpenGL widgets as an ActiveX (executable)</h1>
The ActiveX control in this example uses the QGlWidget class in
Qt to render an OpenGL scene in an ActiveX. The control exposes a few
methods to change the scene. The example is based on the
<a href="opengl-box-example.html">"box" example</a> from the standard
Qt distribution.
<p> The example demonstrates the use of the default factory and
<a href="qaxfactory.html#isServer">QAxFactory::isServer</a>(), and the implementation of an additional COM
interface using <a href="qaxbindable.html">QAxBindable</a> and <a href="qaxaggregated.html">QAxAggregated</a>. The server executable
can run both as an ActiveX server and as a stand alone application.
<p>
The application uses the default factory as provided by the
<a href="qaxfactory.html#QAXFACTORY_DEFAULT">QAXFACTORY_DEFAULT</a> macro to expose the <tt>GLBox</tt> widget as an ActiveX
control.
<pre> #include <<a href="qaxfactory-h.html">qaxfactory.h</a>>
QAXFACTORY_DEFAULT( GLBox,
"{5fd9c22e-ed45-43fa-ba13-1530bb6b03e0}",
"{33b051af-bb25-47cf-a390-5cfd2987d26a}",
"{8c996c29-eafa-46ac-a6f9-901951e765b5}",
"{2c3c183a-eeda-41a4-896e-3d9c12c3577d}",
"{83e16271-6480-45d5-aaf1-3f40b7661ae4}"
)
</pre>The implementation of <tt>main</tt> initializes the <a href="qapplication.html">QApplication</a> object,
and uses <a href="qaxfactory.html#isServer">QAxFactory::isServer</a>() to determine whether or not it is
appropriate to create and show the application interface.
<pre> /*
The main program is here.
*/
int main( int argc, char **argv )
{
<a name="x2732"></a> QApplication::<a href="qapplication.html#setColorSpec">setColorSpec</a>( QApplication::CustomColor );
<a href="qapplication.html">QApplication</a> a(argc,argv);
if ( !QGLFormat::hasOpenGL() ) {
<a href="qapplication.html#qWarning">qWarning</a>( "This system has no OpenGL support. Exiting." );
return -1;
}
if ( !QAxFactory::isServer() ) {
GLObjectWindow w;
w.<a href="qwidget.html#resize">resize</a>( 400, 350 );
<a name="x2733"></a> a.<a href="qapplication.html#setMainWidget">setMainWidget</a>( &w );
w.<a href="qwidget.html#show">show</a>();
return a.<a href="qapplication.html#exec">exec</a>();
}
<a name="x2731"></a> return a.<a href="qapplication.html#exec">exec</a>();
}
</pre>
<p>
The <tt>GLBox</tt> class inherits from both the <a href="qglwidget.html">QGLWidget</a> class to be able
to render OpenGL, and from <a href="qaxbindable.html">QAxBindable</a>.
<pre> #include <<a href="qaxbindable-h.html">qaxbindable.h</a>>
class GLBox : public <a href="qglwidget.html">QGLWidget</a>,
public QAxBindable
{
<a href="metaobjects.html#Q_OBJECT">Q_OBJECT</a>
</pre>The class reimplements the <a href="qaxbindable.html#createAggregate">QAxBindable::createAggregate</a>() function from <a href="qaxbindable.html">QAxBindable</a>
to return the pointer to a <a href="qaxaggregated.html">QAxAggregated</a> object.
<pre> public:
GLBox( <a href="qwidget.html">QWidget</a>* parent, const char* name );
~GLBox();
<a href="qaxaggregated.html">QAxAggregated</a> *createAggregate();
public slots:
void setXRotation( int degrees );
</pre>The rest of the class declaration and the implementation of the OpenGL
rendering is identical to the original "box" example.
<p>
The implementation file of the <tt>GLBox</tt> class includes the <tt>objsafe.h</tt>
system header, in which the <tt>IObjectSafety</tt> COM interface is defined.
<pre> #include <objsafe.h>
</pre>A class <tt>ObjectSafetyImpl</tt> is declared using multiple inheritance
to subclass the <a href="qaxaggregated.html">QAxAggregated</a> class, and to implement the IObjectSafety
interface.
<pre> class ObjectSafetyImpl : public <a href="qaxaggregated.html">QAxAggregated</a>,
public IObjectSafety
{
public:
</pre>The class declares a default constructor, and implements the queryInterface
function to support the IObjectSafety interface.
<pre> ObjectSafetyImpl() {}
long queryInterface( const <a href="quuid.html">QUuid</a> &iid, void **iface )
{
*iface = 0;
if ( iid == IID_IObjectSafety )
*iface = (IObjectSafety*)this;
else
return E_NOINTERFACE;
AddRef();
return S_OK;
}
</pre>Since every COM interface inherits <tt>IUnknown</tt> the <tt>QAXAGG_IUNKNOWN</tt> macro
is used to provide the default implementation of the <tt>IUnknown</tt> interface.
The macro is defined to delegate all calls to <tt>QueryInterface</tt>, <tt>AddRef</tt>
and <tt>Release</tt> to the interface returned by the controllingUnknown() function.
<pre> QAXAGG_IUNKNOWN;
</pre>The implementation of the <tt>IObjectSafety</tt> interface provides the caller
with information about supported and enabled safety options, and returns
<tt>S_OK</tt> for all calls to indicate that the ActiveX control is safe.
<pre> HRESULT WINAPI GetInterfaceSafetyOptions( REFIID riid, DWORD *pdwSupportedOptions, DWORD *pdwEnabledOptions )
{
*pdwSupportedOptions = INTERFACESAFE_FOR_UNTRUSTED_DATA | INTERFACESAFE_FOR_UNTRUSTED_CALLER;
*pdwEnabledOptions = INTERFACESAFE_FOR_UNTRUSTED_DATA | INTERFACESAFE_FOR_UNTRUSTED_CALLER;
return S_OK;
}
HRESULT WINAPI SetInterfaceSafetyOptions( REFIID riid, DWORD pdwSupportedOptions, DWORD pdwEnabledOptions )
{
return S_OK;
}
};
</pre>The implementation of the <tt>createAggregate()</tt> function just returns a new
<tt>ObjectSafetyImpl</tt> object.
<pre> QAxAggregated *GLBox::createAggregate()
{
return new ObjectSafetyImpl();
}
</pre>
<p> To build the example you must first build the <a href="qaxserver.html">QAxServer</a> library. Then run qmake and your make tool in
<tt>examples/wrapper</tt>.
<p> <hr>
<p> The <a href="qaxserver-demo-opengl.html">demonstration</a> requires your
WebBrowser to support ActiveX controls, and scripting to be enabled.
<p> In contrast to the other QAxServer examples Internet Explorer will not
open a dialog box to ask the user whether or not the scripting of the GLBox
control should be allowed (the exact browser behaviour depends on the security
settings in the Internet Options dialog).
<p>
<pre> <SCRIPT LANGUAGE=JavaScript>
function setRot( form )
{
GLBox.setXRotation( form.XEdit.value );
GLBox.setYRotation( form.YEdit.value );
GLBox.setZRotation( form.ZEdit.value );
}
</SCRIPT>
<p>
An OpenGL scene:<br>
<object ID="GLBox" CLASSID="CLSID:5fd9c22e-ed45-43fa-ba13-1530bb6b03e0"
CODEBASE=http://www.trolltech.com/demos/openglax.cab>
[Object not available! Did you forget to build and register the server?]
</object><br>
<form>
Rotate the scene:<br>
X:<input type="edit" ID="XEdit" value="0"><br>
Y:<input type="edit" name="YEdit" value="0"><br>
Z:<input type="edit" name="ZEdit" value="0"><br>
<input type="button" value="Set" onClick="setRot(this.form)">
</form>
</pre><p>See also <a href="qaxserver-examples.html">The QAxServer Examples</a>.
<!-- eof -->
<p><address><hr><div align=center>
<table width=100% cellspacing=0 border=0><tr>
<td>Copyright © 2007
<a href="troll.html">Trolltech</a><td align=center><a href="trademarks.html">Trademarks</a>
<td align=right><div align=right>Qt 3.3.8</div>
</table></div></address></body>
</html>
|