11.
Creating ActiveX Documents
Creating the ActiveX Document
Project:
Open
the
code
window
and
enter
the
codes
as
shown
in
the
figure
2a. Save
the
form
and
the
project
separately
the
form
is
saved
as
demodocform.dob
and
the
project
is
saved
as
demodocproject.vbp.
Private
Sub
Command1_Click()
Text1.Text
=
ctof(CDbl(Text1.Text))
End
Sub
Private
Sub
Command2_Click()
Text1.Text
=
ftoc(CDbl(Text1.Text))
End
Sub
Function
ftoc(temp
As
Double)
As
Double
ftoc
=
(temp
-
32)
* 5
/ 9
End
Function
Function
ctof(temp
As
Double)
As
Double
ctof
=
temp
* (9
/ 5)
+ 32
End
Function
Figure
2a
Then
select
‘Make
demodocproj.DLL’
from
the
File
menu. This
will
create
a
document
file
named
demodocform.vbd. Open
the
Internet
Explorer
and
view
the
file
‘demodocform.vbd’.
The
project
appears
as
shown
in
the
figure
3
and
you
can
interact
with
it
as
you
do
with
any
Standard
EXE
project.

Figure
3
Creating
the
ActiveX
Document
from
an
existing
Standard
ActiveX
EXE
Project:
Suppose
you
create
a
Standard
EXE
project
to
draw
a
color
gradient. The
design
window
of
the
color
gradient
project
looks
as
in
the
figure
4. It
contains
one
Picture
box
control
and
three
command
button
controls
as
shown
in
the
figure
4. Open
the
code
window
and
enter
the
codes
as
shown
in
the
figure
4a.
Save
and
run
the
project
and
see
that
the
color
gradient
works
properly. You
can
experiment
with
different
starting
and
ending
colors
for
the
gradient
by
changing
the
values
of
the
variables
color1
and
color2.

Figure
4
Private
Sub
Command1_Click()
Dim
newcolor
As
Long
Dim
ipixel,
pwidth
As
Integer
Dim
redinc,
greeninc,
blueinc
As
Single
Dim
color1
As
Long,
color2
As
Long
color1
=
RGB(255,
255,
0)
color2
=
RGB(0,
0,
0)
startred
=
getred(color1)
endred
=
getred(color2)
startgreen
=
getgreen(color1)
endgreen
=
getgreen(color2)
startblue
=
getblue(color1)
endblue
=
getblue(color2)
pwidth
=
Picture1.ScaleWidth
redinc
= (endred
-
startred)
/
pwidth
greeninc
= (endgreen
-
startgreen)
/
pwidth
blueinc
= (endblue
-
startblue)
/
pwidth
For
ipixel
= 0
To
pwidth
- 1
newcolor
=
RGB(startred
+
redinc
*
ipixel,
startgreen
+
greeninc
*
ipixel,
startblue
+
blueinc
*
ipixel)
Picture1.Line
(ipixel,
0)-(ipixel,
Picture1.Height
-
1),
newcolor
Next
End
Sub
Function
getred(colorval
As
Long)
As
Integer
getred
=
colorval
Mod
256
End
Function
Function
getgreen(colorval
As
Long)
As
Integer
tgreen
= ((colorval
And
&HFF00FF)
/
256&)
End
Function
Function
getblue(colorval
As
Long)
As
Integer
getblue
= (colorval
And
&HFF0000)
/
(256&
*
256&)
End
Function
Figure
4a
   |