Active X Controls

Hello:

Was wondering if anyone could provide a good resource for creating Active X controls to be used within an webpage.  Im wanting to create a small message center using an activex control(s).

To Give an example, I'd like to have a form used to send email that has the To and CC Buttons on it.  When one clicks on the To button, a list of recipients is presented in a popup box, which can be selected to send the messages to...

Is this possible?

Thanks
LVL 4
escheiderAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
cwreaConnect With a Mentor Software CraftsmanCommented:
OK, I've cooked up an example.

Here are the important pieces:

----- 8< FireEvtCtl.ctl 8< -----
VERSION 5.00
Begin VB.UserControl FireEvtCtl
   ClientHeight    =   2235
   ClientLeft      =   0
   ClientTop       =   0
   ClientWidth     =   4800
   ScaleHeight     =   2235
   ScaleWidth      =   4800
   Begin VB.TextBox txtTo
      Height          =   405
      Left            =   1080
      TabIndex        =   3
      Text            =   "sample@example.com"
      Top             =   360
      Width           =   2295
   End
   Begin VB.TextBox txtMessage
      Height          =   975
      Left            =   720
      MultiLine       =   -1  'True
      ScrollBars      =   2  'Vertical
      TabIndex        =   1
      Text            =   "FireEvtCtl.ctx":0000
      Top             =   840
      Width           =   3495
   End
   Begin VB.CommandButton cmdSend
      Caption         =   "Send"
      Height          =   375
      Left            =   3480
      TabIndex        =   0
      Top             =   360
      Width           =   735
   End
   Begin VB.Label lblTo
      Caption         =   "To"
      Height          =   375
      Left            =   720
      TabIndex        =   2
      Top             =   360
      Width           =   375
   End
End
Attribute VB_Name = "FireEvtCtl"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = True
Public Event SendButtonClicked()

Private Sub cmdSend_Click()
    RaiseEvent SendButtonClicked
End Sub

Public Property Get Recipient() As String
    Recipient = txtTo.Text
End Property

Public Property Get MessageBody() As String
    MessageBody = txtMessage.Text
End Property
----- 8< END FireEvtCtl.ctl 8< -----


----- 8< FireEvtCtl.html 8< -----
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
      <TITLE>FireEvtCtl Sample</TITLE>
</HEAD>
      <BODY>
            <OBJECT id=FireEvtCtl classid=clsid:54919B55-D6DB-4AFD-895B-815E999A41E4></OBJECT>
      </BODY>
</HTML>
<SCRIPT LANGUAGE="JavaScript">
<!--
function FireEvtCtl::SendButtonClicked()
{
      alert("The send button was clicked!");
      alert("Contents of the Recipient property: " + FireEvtCtl.Recipient);
      alert("Contents of the MessageBody property: " + FireEvtCtl.MessageBody);
}
-->
</SCRIPT>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
      <TITLE>FireEvtCtl Sample</TITLE>
</HEAD>
      <BODY>
            <OBJECT id=FireEvtCtl classid=clsid:XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX></OBJECT>
      </BODY>
</HTML>
<SCRIPT LANGUAGE="JavaScript">
<!--
function FireEvtCtl::SendButtonClicked()
{
      alert("The send button was clicked!");
      alert("Contents of the Recipient property: " + FireEvtCtl.Recipient);
      alert("Contents of the MessageBody property: " + FireEvtCtl.MessageBody);
}
-->
</SCRIPT>
----- 8< END FireEvtCtl.html 8< -----


So, you'll see that I created an ActiveX control in Visual Basic.  The control UI has a few elements: a recipient, a message body, and a send button.  Externally, the control shows a Recipient property, a MessageBody property, and an event called SendButtonClicked that gets fired when the user clicks on the Send button.

In the web page that hosts the control, you'll see it is pretty simple:  the <OBJECT> tag declares the object.  (Replace the XXXXXX's with your own object's class id.)  Then there's a scripting block, called only when the user clicks the Send button in the control.  The event handler shows message boxes, showing that the event occurred, and then demonstrating retrieving those values out of the control properties.  Note that instead of simply calling alert() three times, you could have had it place those property values into HTML form fields, and then submit the form automatically.

(Bear in mind, the example should work on your own machine, but if you don't mark the control as safe and get it signed, other users won't be so lucky :-)
0
 
cwreaSoftware CraftsmanCommented:
You'll want a good book on the subject.  One that's pretty good is "Developing Com/Activex Components With Visual Basic 6" by Dan Appleman, ISBN: 1562765760.

There are many other excellent books on building ActiveX controls, but most of them center on C++.  (My favorites are "Designing and Using ActiveX Controls" by Tom Armstrong, and also "ATL Developer's Guide" by the same author.)

One thing to keep in mind when developing controls for the web is to keep them lightweight.  That is, do not overload them with resources, and do not have too many dependencies on third party libraries or controls.  If you're building your control with Visual Basic, you'll at the very least have to depend on the VB run-time library.  I'd try and avoid anything else because deployment of your control can get tricky.

The next thing to keep in mind for controls used in a web page is that they must be safe, and signed.  Safe means you need to make sure your control can't be abused by other people to perform privileged operations on the client meachine.  Signed means you'll need to get a software publisher's certificate from somebody like Verisign before you can host your controls in a page and expect people to be able to use them.  (Most people have their browsers set to refuse controls that are not signed.)

Here's a reference on control safety:

http://msdn.microsoft.com/library/default.asp?url=/workshop/components/activex/security.asp

Here are some references for signing controls, deployment issues, etc:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaxctrl/html/msdn_signmark.asp

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaxctrl/html/msdn_deplactx.asp

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon98/html/vbconunderstandingdigitalsigning.asp

Hope this helps.
0
 
escheiderAuthor Commented:
any other online resources?

Im looking for information on the following with ActiveX and webpages:

1.  Sending values from the ActiveX control to a webpage


Also, need help on specific issues:

1. Do ActiveX controls need to reside in a <form></form> tag?
2. How does one pull values from  the data values in the activex control?
3. How do you pass values from one control to the other?
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
escheiderAuthor Commented:
One last question:

Can you cause the form to be submitted from within the control?
0
 
cwreaSoftware CraftsmanCommented:
First Q#1. When you ask "Sending values from the ActiveX control to a web page" do you mean communicating with a script on the server, or do you mean communicating with a web page that is loaded in the browser and hosting your control? The answer to both is "yes".  The first type requires your control to talk HTTP with the web server.  The second type can be accomplished by having your control fire events, and then having JScript or VBScript in the web page handle the events and set form fields accordingly.

Second Q#1: No, as far as I know, they don't need to reside in a form.  There are many places where you might want to use an ActiveX control not in a form.

Q#2:  You can access properties and methods on the control using web page scripting (JScript, VBScript.)

Q#3:  With scripting.  Generally, you don't want your control to know about other controls on the page.  You leave integration of that kind up to user of the controls.

Last question:  You can have your control fire an event, and then have web page scripting submit a form when that event is received.

0
 
cwreaSoftware CraftsmanCommented:
Note that there is the possibility of creating a control that is aware of the DHTML object model; and can thus directly set fields on your page, etc.  However I would recommend you create your controls to use standard properties, methods, and events and let the control user decide how to best call them.  That way your control can be hosted in multiple environments (e.g. VB), not just in a web page.
0
 
escheiderAuthor Commented:
Thanks for your help cwrea:

Let me give you a specific example:

Im creating a control that looks similiar to outlook with the to, cc, subject and message body objects located in the ocx.

At the bottom of the control are two controls, send and cancel.  When I click send, it processes the data by sending it to an access database, then just sits there.  I'd like to have the web page change to a different asp page after the send button is pressed, but don't know how to trigger a script that this button has been pressed.  Im familiar with vbscript, but haven't dealt with ocx controls.

I'll give you specific code if you'll help.
0
 
cwreaSoftware CraftsmanCommented:
Whoops, had that HTML inserted twice by mistake.  Sorry :-)
0
 
cwreaSoftware CraftsmanCommented:
Note that by using ActiveX controls you may be limited to users with Internet Explorer on Windows platforms.
0
 
escheiderAuthor Commented:
Fantastic...just what I was looking for.  I would have never figured this out by myself...

Any good web references talking about this stuff directly?  Im not too worried about the other platforms, as they will be a Windows environment using IE 5+
0
 
escheiderAuthor Commented:
Cwrea:

Can I ask you one more question so I don't have to spend another 50 points?
0
 
cwreaSoftware CraftsmanCommented:
Regarding web references, you can't go wrong with a lot of the material at the Microsoft Developer Network (http://msdn.microsoft.com).  Excellent site.

I also like a tool called Copernic (http://www.copernic.com) that lets me search multiple engines simultaneously.  Often with a judicious choice of keywords and the Copernic's "refine" feature, solutions to problems are easy to find.  Try it out.

Regarding one last question, sure, if it's easy and quick :-)

0
 
escheiderAuthor Commented:
Thanks...

Here is my question.  On the user control, I have the To and CC button, which, when clicked, spawns an additional vbform to allow the user to select who he will send a message to.  Question is, how to I return these results back to the user control when completed?  I've tried a couple of things, but, as you know, Im not familiar enough with user controls..
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.