HOWTO: Tell if Internet Explorer is Offline from an ActiveX DocID: Q200027
|
When developing Internet applications, developers need to account for end users with a wide variety of system environments with different ways of connecting to the Internet. This ActiveX Document sample code demonstrates how to tell if Internet Explorer is offline.
Use the following sample code to determine if Internet Explorer is offline:
Dim bOffline As Boolean
Private Function get_Offline() As Boolean ' (VARIANT_BOOL * bOffline)
Dim hr As Long
Dim ci As INTERNET_CONNECTED_INFO
Dim ci_len As Long
ci_len = 8
Dim ret As Long
ret = InternetQueryOption(0&, INTERNET_OPTION_CONNECTED_STATE, _
ci, ci_len)
get_Offline = Not ((ci.dwConnectedState And INTERNET_STATE_CONNECTED) =
INTERNET_STATE_CONNECTED)
End Function
Private Sub put_Offline(bOffline As Boolean)
Dim hr As Long
Dim ci As INTERNET_CONNECTED_INFO
Dim ret As Long
If bOffline Then
ci.dwConnectedState = INTERNET_STATE_DISCONNECTED_BY_USER
ci.dwFlags = ISO_FORCE_DISCONNECTED
Else
ci.dwConnectedState = INTERNET_STATE_CONNECTED
End If
ret = InternetSetOption(0&, INTERNET_OPTION_CONNECTED_STATE, _
ci, LenB(ci))
End Sub
Private Sub Command1_Click()
MsgBox "Offline = " & get_Offline()
End Sub
Private Sub Command2_Click()
put_Offline True
End Sub
Option Explicit
Public Type INTERNET_CONNECTED_INFO
dwConnectedState As Long
dwFlags As Long
End Type
Public Declare Function InternetSetOption Lib "wininet.dll" Alias _
"InternetSetOptionA" (ByVal hInternet As Long, _
ByVal lOption As Long, ByRef sBuffer As Any, _
ByVal lBufferLength As Long) As Integer
' Queries an Internet option on the specified handle
Public Declare Function InternetQueryOption Lib "wininet.dll" Alias _
"InternetQueryOptionA" (ByVal hInternet As Long, _
ByVal lOption As Long, ByRef sBuffer As Any, _
ByRef lBufferLength As Long) As Integer
Public Const INTERNET_OPTION_CONNECTED_STATE = 50
Public Const INTERNET_STATE_CONNECTED = 1
' // disconnected from network
Public Const INTERNET_STATE_DISCONNECTED = 2
' 0x00000010 // disconnected by user request
Public Const INTERNET_STATE_DISCONNECTED_BY_USER = &H10
'// no network requests being made (by Wininet)
Public Const INTERNET_STATE_IDLE = &H100
'// network requests being made (by Wininet)
Public Const INTERNET_STATE_BUSY = &H200
'//
'// ISO_FORCE_DISCONNECTED -
'// if set when putting Wininet into disconnected mode,
'// all outstanding requests will be aborted with a cancelled error
'//
Public Const ISO_FORCE_DISCONNECTED = 1
Additional query words: kbDSupport
Keywords : kbActiveDocs kbInternet kbVBp kbVC500 kbVC600 kbIE401sp1 kbIE401sp2 kbGrpInet kbIE500
Version : WINDOWS:4.0,4.01,4.01 SP1,4.01 SP2,5.0,6.0
Platform : WINDOWS
Issue type : kbhowto
Last Reviewed: May 8, 1999