VERSION 5.00
Begin VB.Form frmMain
BorderStyle = 3 'Fixed Dialog
Caption = "DUN Test"
ClientHeight = 3195
ClientLeft = 45
ClientTop = 330
ClientWidth = 4680
LinkTopic = "Form1"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 3195
ScaleWidth = 4680
ShowInTaskbar = 0 'False
StartUpPosition = 2 'CenterScreen
Begin VB.CommandButton cmdCheck
Caption = "C&heck Connection"
Height = 495
Left = 1740
TabIndex = 6
Top = 1260
Width = 1215
End
Begin VB.TextBox txtStatus
Height = 975
Left = 60
Locked = -1 'True
MultiLine = -1 'True
ScrollBars = 2 'Vertical
TabIndex = 4
Top = 2160
Width = 4575
End
Begin VB.ListBox lstConnections
Height = 840
Left = 60
TabIndex = 3
Top = 360
Width = 4515
End
Begin VB.CommandButton cmdDisconnect
Caption = "&DISCONNECT"
Height = 495
Left = 3360
TabIndex = 1
Top = 1260
Width = 1215
End
Begin VB.CommandButton cmdConnect
Caption = "C&ONNECT"
Height = 495
Left = 60
TabIndex = 0
Top = 1260
Width = 1215
End
Begin VB.Label lblHeadings
Caption = "Status"
Height = 255
Index = 1
Left = 60
TabIndex = 5
Top = 1920
Width = 975
End
Begin VB.Label lblHeadings
Caption = "&Connections"
Height = 255
Index = 0
Left = 60
TabIndex = 2
Top = 60
Width = 975
End
End
Attribute VB_Name = "frmMain"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Private WithEvents fInet As WinInet
Private Sub cmdCheck_Click()
If fInet.Connected Then
Call AddToStatus("Internet Connection active.")
Else
Call AddToStatus("No active Internet Connection.")
End If
End Sub
Private Sub cmdConnect_Click()
Dim plResult As Long
If lstConnections.ListIndex = -1 Then
MsgBox "Please select a DUN from the listbox before selecting connect.", vbOKOnly + vbExclamation, "WinInet Demo"
Else
plResult = fInet.StartDUN(Me.hWnd, lstConnections.List(lstConnections.ListIndex))
If plResult = 0& Then
Call AddToStatus("Connection to " & lstConnections.List(lstConnections.ListIndex) & " made.")
Else
If plResult = -1 Then
Call AddToStatus("Already connected.")
Else
Call AddToStatus("Error " & plResult & " attempting to connect to " & lstConnections.List(lstConnections.ListIndex))
End If
End If
End If
End Sub
Private Sub cmdDisconnect_Click()
Dim plResult As Long
plResult = fInet.HangUp
If plResult = 0& Then
Call AddToStatus("Connection terminated.")
Else
If plResult = -1 Then
Call AddToStatus("No connection made yet.")
Else
Call AddToStatus("Unable to terminate connection, error: " & plResult)
End If
End If
End Sub
Private Sub fInet_ConnectionClosed()
'this event does not "monitor" the connection status, it is only fired when
'the .HangUp method is invoked
Call AddToStatus("Connection closed event fired.")
End Sub
Private Sub fInet_ConnectionMade()
'this event does not "monitor" the connection status, it is fired when a
'successfull connection is made via the .StartDUN method
Call AddToStatus("Connection made event fired.")
End Sub
Private Sub Form_Load()
Dim psDuns() As String
Dim piMax As Integer
Dim piIndex As Integer
'initialize class
Set fInet = New WinInet
'get list of DUNS on the system
fInet.ListDUNs psDuns
lstConnections.Clear
'put list in the listbox
piMax = -1
On Error Resume Next
piMax = UBound(psDuns())
On Error GoTo 0
For piIndex = 0 To piMax
lstConnections.AddItem psDuns(piIndex)
Next piIndex
txtStatus.Text = "Class initialized." & vbCrLf
End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
'clear reference to class
Set fInet = Nothing
End Sub
Private Sub AddToStatus(psText As String)
'add supplied text to box
txtStatus.Text = txtStatus.Text & psText & vbCrLf
'scroll text down if necessary
txtStatus.SelStart = Len(txtStatus.Text)
txtStatus.SelLength = 0
End Sub