Weblink ActiveX

Learn to make a WebLink ActiveX control using Visual Basic 6 with this Tutorial that Celebrates the CESPage 25th Anniversary

This is a simple program, which will introduce you to ActiveX Controls, Functions, Properties, Methods and the Win32 API.

Step 1

Load Microsoft Visual Basic, then select ActiveX Control Project if VB5/6, click on the option then click Open
New ActiveX Project

Step 2

A Blank UserControl named UserControl1 should then appear
Blank UserControl

Step 3

Then from the Visual Basic Components Menu Select the Label Control:
Label Control

Step 4

Draw a Label on the UserControl
UserControl with Label

Step 5

Change the Name of Label1 to lblWeblink and the Caption to Weblink Control
UserControl with Label

Step 6

On the Visual Basic Menu Bar select Add-Ins | Add-in Manager..., select the VB ActiveX Control Interface Wizard
Add-in Manager

Step 7

Click on Ok then Select Add-Ins | ActiveX Control Interface Wizard... from the Visual Basic menu and a Wizard Dialog should appear,
VB ActiveX Control Interface Wizard

Step 8

Click on Next and the Select Interface Members stage should appear, in the Available Names Listbox add using the > Button the move the Alignment and Caption Property to the Selected Names Listbox
Select Interface Members

Step 9

Click on Next and the Create Custom Interface Members stage should appear
Create Custom Interface Members

Step 10

Click on New... for the Add Custom Member Dialog, then type in the Name Text Box Location and select the Property Option from the Type Radio Buttons and Click on Ok
Add Custom Member

Step 11

Click on Next for the Set Mapping Stage and change the Maps To Control Combobox selection to lblWeblink for all Properties/Events/Methods except the Location Property
Set Mapping

Step 12

Click on Next for the Set Attributes Stage and Select the Location Property from the Public Name Listbox and change the Attribute Information for Data Type to String and type in a meaningful Description
Set Attributes

Step 13

Click on Next and then Finish to create the items selected in the Wizard a Summary Report will also be created, it is recommended that you read this for extra ActiveX information

Step 14

Double Click on the UserControl and at the bottom of the General Declarations Section type in:


Private Declare Function ShellExecute Lib "shell32.dll" Alias
"ShellExecuteA" (ByVal hWnd As Long, ByVal lpOperation As String, ByVal 
lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, 
ByVal nShowCmd As Long) As Long

Public Function HyperJump(ByVal URL As String) As Long
    On Error Resume Next
    HyperJump = ShellExecute(0&, vbNullString, URL, vbNullString, vbNullString, vbNormalFocus)
End Function
                                    

Step 15

Double Click on the UserControl and type in the UserControl_Resize Sub:


' Move to 0,0 and resize lblWeblink to control size
lblWeblink.Top = 0
lblWeblink.Left = 0
lblWeblink.Width = UserControl.Width
lblWeblink.Height = UserControl.Height
lblWeblink.FontUnderline = True 
                                    

Step 16

Double Click on the Label for Weblink Control or lblWeblink and type in the cmdWeblink_Click() Sub (remove the RaiseEvent Click line)


HyperJump (m_Location) 
                                    

Step 17

Close the UserControl Window (click on the X in the Top Right Corner), then select File | Add Project... from the Visual Basic menu then add a Standard EXE Project
Add Project

Step 18

A Blank Form named Form1 should then appear
Blank Form

Step 19

Then from the Visual Basic Components Menu Select the Weblink Control:
Weblink Control

Step 20

Draw a Weblink on the Form
Form with Weblink Control

Step 21

Double Click on the Form of Form1 and type in the Form_Load() Sub:


Weblink1.Caption = "Windows Folder"
Weblink1.ForeColor = vbBlue
Weblink1.Location = "file://c:\windows"
                                    

Step 22

Save the Project, for example for example prjWeblink for the ActiveX, prjWebLinkTest for the Project and grpWeblinkControl for the Project Group, into a vacant folder as you have finished the application. Click on Start / Run
Start / Run
This should Start the application
Weblink ActiveX Running

Step 23

Click on the Blue Hyperlink style Text to Open the Windows Folder or whatever the Location property is set to To Exit the application, Click the X button on the Top Right of the Form or End / Stop
End / Stop

You have just created a simple Weblink ActiveX control using the Interface Wizard and Win32 API. Try adding extra Properties such as FontUnderline and see what else you can achieve with this program.