7 |
The LA Fox Developer Newsletter
August
1997
Implementation of ActiveX
Controls in Visual FoxPro
Part I
by Michael W Thomas, Rocky Mountain PUG
When you hear "ActiveX" your first thought may be “Internet”.
ActiveX is a technology that reaches far beyond the Internet and
into our Visual FoxPro applications. If you haven’t worked with
ActiveX yet, you will in your next application. We’ll take a brief
look at what ActiveX is all about and then study an example of
implementing ChartFX, an ActiveX graphing tool.
An
ActiveX Primer
Terms
OLE Object
-
An object that can be linked or embedded. OLE
objects include OLE controls and insertable OLE objects
such as Excel spreadsheets and Word documents. (from
Visual FoxPro 3 Help)
ActiveX Control
-
“The
new name for programmable elements
formerly known as OLE controls, OCXs, or OLE custom
controls. Controls previously built with the MFC Control
Developer’s Kit meet the ActiveX control specification.
“An ActiveX control, like a built-in control, is an object that
you place on a form to enable or enhance a user’s interac-
tion with an application. ActiveX controls have events and
can be incorporated into other controls. These controls have
an OCX file name extension.” (from Visual FoxPro 5 Help)
In-Process
-
The command execution thread runs within the
client application’s processing thread. Examples: ChartFX,
TreeView Control
Out-of-Process
-
The command execution thread runs outside
of the client application. The advantage is that the client
application can continue processing while the server works
independently. The disadvantage is that cross-process
communication is slow. Examples: Adobe Acrobat reader,
Graphics Server
MFC
-
Microsoft Foundation Class. ActiveX controls are created
using the MFC’s. Think of them a base classes for VC++
developers.
Acti veX Controls vs. ActiveXAutomation
There
are
two common, yet
very
distinct, implementations of
ActiveX. First is
ActiveX Automation.
This usually refers to
controlling one application within another. An example might be
automatically sending an e-mail message from within an
application. Another may be creating and formathng a Word
document from within VFP. This technology has been around
for a while and is often what was referred to as “doing OLE”.
Probably the most powerful component of ActiveX technology is
the capability to create reusable software components. As VFP
developers we’re familiar with the concepts of classes and
objects. ActiveX components offers the same capability, but
across development
plafforms,
including web page develop-
ment. An ActiveX control, is simply a class that can be instan-
tiated and reused. These controls can be created in VC++ or
VB5.
Flavors of ActiveX Projects
To add to the confusion, ActiveX projects come in five basic
types. In VFP, we commonly only deal with two of them
(sometimes a three), the others are just packaging.
ActiveX EXE.
This is an application that exposes one or
more classes. ActiveX EXE’s expose their object model to
allow ActiveX automation. Examples are Word, Excel, your
own VFP5 application, or Maplnfo. ActiveX EXE’s always
run out-of-process with respect to the client.
An ActiveX Control
is a self-contained class or set of
classes compiled into
an
OCX. ActiveX controls
can
be
instantiated within VB forms, VFP forms, web browsers,
etc. The great advantage of using these for web develop-
ment
is that they are small and run locally. Internet Ex-
plorer 3.0 has facilities built-in
to automatically download,
install, and register
OCX’s as needed when viewing a web
page. Distribution of new
updates happens automatically
when a new version
is posted to the web page using the
OCX
An
ActiveX DLL exposes one or more classes which allow
creation of objects running in-process. These can be
created by VFP5.
(For more information on this topic, see
ActiveX and the Single
Programmer
, Peter G. Aitken;
Visual Developer Magazine;
Apr!
May 1997; Vol
8, Nol; pp. 40-45)
16-bit vs. 32-bit Controls
ActiveX controls can be compiled as 16-bit and 32-bit controls,
much as other applications can. This is a very important
distinction because of incompatibilities between operating
systems and development environments.
To start, let’s say that 32-bit controls cannot run in a 16-bit
environment. However, there are now a few twists. VFP, being a
32-bit language, supports 32-bit (only, but I’ll come back to
this). VFP3 can run
in a 16-bit operating system only with the
W1n32s thunk layer, but remember we already pointed out that
32-bit controls can’t
run
in 16-bit environments, including
Win32s.
[Ed. Note: Michael W. Thomas is a commercial application
developer forResource Data International, Inc. in Boulder, CO.
CIS: 103650,2175; email:
mthomas@resdata.com.]
Page 7
|
7 |