Adding ActiveX Control to HTML-doc

How do you add an ActiveX Control .ocx to a web page?
LVL 2
kristoferAsked:
Who is Participating?
 
Dave_GreeneConnect With a Mentor Commented:
Hope this does it!
0
 
choroqueCommented:
<object id="myid" classid="clsid:your class id" codebase="mycab.cab#Version=5,0,4,15">
<PARAM NAME="myparameter" VALUE="myvalue">
</object>

you can insert the object using ms frontpage or visual interdev. I believe your vb app have an .ocx
files. Just insert the .ocx files using frontpage or interdev (the classid will be automatically created),
then in the "codebase", refer to your cab file.
0
 
kristoferAuthor Commented:
Cab file? how do I get the cab file?? package and deployment wizard?
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
kristoferAuthor Commented:
#Version=5,0,4,15?? how do I know?
0
 
choroqueCommented:
actually, you can just use frontpage or visual interdev to insert the .ocx. Just forget about the cab file if you don't have one. About the version, it will be automatically inserted as you put the .ocx on you web page, just like the classid.
0
 
Dave_GreeneCommented:
Ok, here is the step by step example. USING VB

1) Create an OCX Project (ActiveX Control)
2) right click your control, select add UserControl, then when you get into the VB dialog where you

normally select a usercontrol, select the wizard.
3) Add the Property you want to expose eg (Message) "My Custom Members" in the wizard
4) doesn't map to a control
5) When you get to the set attributes page, set Message to a string.

Your New Control Should Look Like this

'CODE BEGIN

'Default Property Values:
Const m_def_Message = "Empty Message"
'Property Variables:
Dim m_Message As String
'Event Declarations:

'WARNING! DO NOT REMOVE OR MODIFY THE FOLLOWING COMMENTED LINES!
'MemberInfo=13,0,0,Empty Message
Public Property Get Message() As String
Message = m_Message
End Property

Public Property Let Message(ByVal New_Message As String)
m_Message = New_Message
PropertyChanged "Message"
MsgBox "Here is the Message you passed [" & m_Message & "]"
End Property

'Initialize Properties for User Control
Private Sub UserControl_InitProperties()
m_Message = m_def_Message
End Sub

'Load property values from storage
Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
m_Message = PropBag.ReadProperty("Message", m_def_Message)
End Sub

'Write property values to storage
Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
Call PropBag.WriteProperty("Message", m_Message, m_def_Message)
End Sub

'CODE END

6) Build your OCX
7) set binary compatibility on the control in the projects properties.
8) Add a standard EXE to your project group
9) Place the Control onto form1.
10) Check to see if the value you set in the controls property page (on form1) actually change the value,



if so proceed.

If not, it's time to write a comment on EE stating so. (listing the control code)
11) it worked!  yahoo!  Now build your OCX again just to be certain you have any changes
12) Use the Package and Deployment wizard to build the deployment
- Using the "Internet Package" option
- Take the defaults until you get to the "Safety Settings" tab, you will select "NO" for Safe for

Scripting, and

"YES" for safe for initialization.
- Now you are finished... with this step
13) now look into the directory where you built the package. you should see projectName.htm, open it


It should look something like this

'HTML BEGIN

<HTML>
<HEAD>
<TITLE>Project1.CAB</TITLE>
</HEAD>
<BODY>
<!--     If any of the controls on this page require licensing, you must
 create a license package file. Run LPK_TOOL.EXE to create the
 required LPK file. LPK_TOOL.EXE can be found on the ActiveX SDK,
 http://www.microsoft.com/intdev/sdk/sdk.htm. If you have the Visual
 Basic 6.0 CD, it can also be found in the \Tools\LPK_TOOL directory.

 The following is an example of the Object tag:

<OBJECT CLASSID="clsid:5220cb21-c88d-11cf-b347-00aa00a28331">
 <PARAM NAME="LPKPath" VALUE="LPKfilename.LPK">
</OBJECT>
-->

<OBJECT ID="UserControl1"
CLASSID="CLSID:291EACFF-517D-4B6C-9EF0-A329A541AD8C"
CODEBASE="Project1.CAB#version=1,0,0,0">
</OBJECT>
</BODY>
</HTML>

'HTML END

14) Make the following changes (per this example)
   <OBJECT ID="UserControl1" Height="400" Width="400"  <--however big the control is
 CLASSID="CLSID:291EACFF-517D-4B6C-9EF0-A329A541AD8C"
 CODEBASE="Project1.CAB#version=1,0,0,0">
    <param name="Message" value="Your New Message here!">
15) Save your changes and run the projectname.htm
16) If it works great, if not... time to comment again  :)

Cheers!  
0
 
dluediCommented:
Hi kristofer, If you've got Windows Mediaplayer here is an much easier example:
Just copy this and save it as e.x: test.htm



<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>This is an Activ-X Test</title>
</head>

<body>

<p>
<object classid="clsid:22D6F312-B0F6-11D0-94AB-0080C74C7E95" id="MediaPlayer1" width="286" height="225">
  <param name="AudioStream" value="-1">
  <param name="AutoSize" value="-1">
  <param name="AutoStart" value="-1">
  <param name="AnimationAtStart" value="-1">
  <param name="AllowScan" value="-1">
  <param name="AllowChangeDisplaySize" value="-1">
  <param name="AutoRewind" value="0">
  <param name="Balance" value="0">
  <param name="BaseURL" value>
  <param name="BufferingTime" value="5">
  <param name="CaptioningID" value>
  <param name="ClickToPlay" value="-1">
  <param name="CursorType" value="0">
  <param name="CurrentPosition" value="-1">
  <param name="CurrentMarker" value="0">
  <param name="DefaultFrame" value>
  <param name="DisplayBackColor" value="0">
  <param name="DisplayForeColor" value="16777215">
  <param name="DisplayMode" value="0">
  <param name="DisplaySize" value="0">
  <param name="Enabled" value="-1">
  <param name="EnableContextMenu" value="-1">
  <param name="EnablePositionControls" value="-1">
  <param name="EnableFullScreenControls" value="0">
  <param name="EnableTracker" value="-1">
  <param name="Filename" value>
  <param name="InvokeURLs" value="-1">
  <param name="Language" value="-1">
  <param name="Mute" value="0">
  <param name="PlayCount" value="1">
  <param name="PreviewMode" value="0">
  <param name="Rate" value="1">
  <param name="SAMILang" value>
  <param name="SAMIStyle" value>
  <param name="SAMIFileName" value>
  <param name="SelectionStart" value="-1">
  <param name="SelectionEnd" value="-1">
  <param name="SendOpenStateChangeEvents" value="-1">
  <param name="SendWarningEvents" value="-1">
  <param name="SendErrorEvents" value="-1">
  <param name="SendKeyboardEvents" value="0">
  <param name="SendMouseClickEvents" value="0">
  <param name="SendMouseMoveEvents" value="0">
  <param name="SendPlayStateChangeEvents" value="-1">
  <param name="ShowCaptioning" value="0">
  <param name="ShowControls" value="-1">
  <param name="ShowAudioControls" value="-1">
  <param name="ShowDisplay" value="0">
  <param name="ShowGotoBar" value="0">
  <param name="ShowPositionControls" value="-1">
  <param name="ShowStatusBar" value="0">
  <param name="ShowTracker" value="-1">
  <param name="TransparentAtStart" value="0">
  <param name="VideoBorderWidth" value="0">
  <param name="VideoBorderColor" value="0">
  <param name="VideoBorder3D" value="0">
  <param name="Volume" value="-9640">
  <param name="WindowlessVideo" value="0">
</object>
</p>

</body>

</html>
0
 
Dave_GreeneCommented:
Questions?
0
 
kristoferAuthor Commented:
Thanks a lot Dave, just what I wanted. Sorry it took so long to reply, but I've been busy and I wanted to try the code...

Everything you've decribed works very well until I try to start html-file. A box comes up: "Some Software (ActiveX Controls) on this page may be unsafe. It is recommended that you not run it. Do you want to allow it to run?" I click yes and then I just see the grey control 400x400 pixels, no msg pops up like it did when I ran the ocx through an exe-project.

any ideas... thx

p.s. increased points to 50
0
 
Dave_GreeneCommented:
hey kristofer,

Post your html source here...  might be the culprit

-d
0
 
kristoferAuthor Commented:
Here it comes...
<HTML>
<HEAD>
<TITLE>Project1.CAB</TITLE>
</HEAD>
<BODY>
<!--     If any of the controls on this page require licensing, you must
     create a license package file. Run LPK_TOOL.EXE to create the
     required LPK file. LPK_TOOL.EXE can be found on the ActiveX SDK,
     http://www.microsoft.com/intdev/sdk/sdk.htm. If you have the Visual
     Basic 6.0 CD, it can also be found in the \Tools\LPK_TOOL directory.

     The following is an example of the Object tag:

<OBJECT CLASSID="clsid:5220cb21-c88d-11cf-b347-00aa00a28331">
     <PARAM NAME="LPKPath" VALUE="LPKfilename.LPK">
</OBJECT>
-->

<OBJECT ID="UserControl1" height="200" width="200"
CLASSID="CLSID:81B0339A-7123-11D5-8F3A-0050DAE6FCFC"
CODEBASE="Project1.CAB#version=1,0,0,0">
<param name="Message" value="Hello all">
</OBJECT>
</BODY>
</HTML>
0
 
Dave_GreeneCommented:
Ok, the html is correct, now it can only be one of two things.  Either the code in your UserControl isn't correct..(Not likely) or your browser settings need to be adjusted to accept unsigned controls.

Goto Tools>Internet Options>Security>Custom Level

Enable every option of ActiveX controls.  For deployment over the internet you would want sign your controls with verisign, but for testing purposes change the options above and try it again.

-d
0
 
Dave_GreeneCommented:
Any word on this one?
0
 
kristoferAuthor Commented:
Not yet, I 'm working on it and will get back to you.
0
 
teacher_modCommented:
Dave_Green,

Looks like they forgot to come back.  Please re-submit with an answer.  If that does not bring them back then I will accept it on their behalf.
TIA for helping to clean up the old questions.

teacher_mod
Community Support Moderator
Experts-Exchange
teacher_mod@experts-exchange.com


0
 
kristoferAuthor Commented:
sorry about the delay
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.