form1,啟動界面。
若檢測到有網路連接,直接跳轉到from2
若檢測到無網路連接,跳轉到from3
謝謝。
uj5u.com熱心網友回復:
Declare Function InternetGetConnectedState Lib "wininet.dll" (ByRef lpdwFlags As Long, ByVal dwReserved As Long) As Long
· lpdwFlags
[out] Pointer to an unsigned long integer variable where the connection description should be returned. This can be a combination of the following values:
INTERNET_CONNECTION_CONFIGURED Local system has a valid connection to the Internet, but it may or may not be currently connected.
INTERNET_CONNECTION_LAN Local system uses a local area network to connect to the Internet.
INTERNET_CONNECTION_MODEM Local system uses a modem to connect to the Internet.
INTERNET_CONNECTION_MODEM_BUSY No longer used.
INTERNET_CONNECTION_OFFLINE Local system is in offline mode.
INTERNET_CONNECTION_PROXY Local system uses a proxy server to connect to the Internet.
INTERNET_RAS_INSTALLED Local system has RAS installed.
· dwReserved
[in] Reserved. Must be set to zero.
Returns TRUE if there is an Internet connection, or FALSE otherwise.
uj5u.com熱心網友回復:
不懂,wininet.dll 是什么?uj5u.com熱心網友回復:
這個api貌似不準
uj5u.com熱心網友回復:
誰有更好的辦法呢?uj5u.com熱心網友回復:
Private Sub InetLogin_StateChanged(ByVal State As Integer) If State = icResponseCompleted Then Dim StrIn As String StrIn = InetLogin.GetChunk(0, icString) If StrIn = "ok" Then '登陸成功 您可在此添加 登陸成功后的動作me.hideform2.show MsgBox "登陸成功,您可以在此添加登陸成功后的動作", vbInformation Else MsgBox StrIn, vbInformation, "登錄失敗" End If ElseIf State = icError Then MsgBox "網路連接錯誤" End IfEnd Sub這個代碼我加入后,最后一個 End IfEnd Sub提示錯誤,我不知道哪里修改?
我想換成若檢測不到連接,跳轉到form3 。
uj5u.com熱心網友回復:
Private Declare Function InternetCheckConnection Lib "wininet.dll" Alias "InternetCheckConnectionA" (ByVal lpszUrl As String, ByVal dwFlags As Long, ByVal dwReserved As Long) As Long
Public Function isConnectInet()
isConnectInet = (InternetCheckConnection("http://www.baidu.com", &H1, 0&) <> 0)
End Function
我用的這個方法檢測網路是否連接的,挺準
uj5u.com熱心網友回復:
我要的效果是 網路存在,立即跳轉到FORM2,檢測不到網路跳轉到 FORM3
uj5u.com熱心網友回復:
那你就在定時器中檢查,每隔1秒鐘檢查一次、
uj5u.com熱心網友回復:
不會啊,求大師兄uj5u.com熱心網友回復:
Private Declare Function InternetCheckConnection Lib "wininet.dll" Alias "InternetCheckConnectionA" (ByVal lpszUrl As String, ByVal dwFlags As Long, ByVal dwReserved As Long) As Long
Public Function isConnectInet()
isConnectInet = (InternetCheckConnection("http://www.baidu.com", &H1, 0&) <> 0)
End Function
Private Sub Form_Load()
If (InternetCheckConnection("http://www.baidu.com", &H1, 0&) <> 0) Then
Form2.Show
Else
Form3.Show
End If
End Sub
uj5u.com熱心網友回復:
Private Declare Function InternetCheckConnection Lib "wininet.dll" Alias "InternetCheckConnectionA" (ByVal lpszUrl As String, ByVal dwFlags As Long, ByVal dwReserved As Long) As Long
Public Function isConnectInet()
isConnectInet = (InternetCheckConnection("http://www.baidu.com", &H1, 0&) <> 0)
End Function
我用的這個方法檢測網路是否連接的,挺準

簡單測驗了一下,開搞timer不斷檢測,然后斷開網路,qq,旺旺立刻就離線了,可函式依然提示true ....
uj5u.com熱心網友回復:
Private Declare Function InternetCheckConnection Lib "wininet.dll" Alias "InternetCheckConnectionA" (ByVal lpszUrl As String, ByVal dwFlags As Long, ByVal dwReserved As Long) As Long
Public Function isConnectInet()
isConnectInet = (InternetCheckConnection("http://www.baidu.com", &H1, 0&) <> 0)
End Function
Private Sub Form_Load()
If (InternetCheckConnection("http://www.baidu.com", &H1, 0&) <> 0) Then
Form2.Show
Else
Form3.Show
End If
End Sub
這種效果是ok的,可是問題是如果無網路,啟動軟體會很慢,,這個可能解決掉?
uj5u.com熱心網友回復:
Private Declare Function InternetCheckConnection Lib "wininet.dll" Alias "InternetCheckConnectionA" (ByVal lpszUrl As String, ByVal dwFlags As Long, ByVal dwReserved As Long) As Long
Public Function isConnectInet()
isConnectInet = (InternetCheckConnection("http://www.baidu.com", &H1, 0&) <> 0)
End Function
Private Sub Form_Load()
If (InternetCheckConnection("http://www.baidu.com", &H1, 0&) <> 0) Then
Form2.Show
Else
Form3.Show
End If
End Sub
怎么跳轉到form2,或者form3的時候自動關閉form1
uj5u.com熱心網友回復:
Private Declare Function InternetCheckConnection Lib "wininet.dll" Alias "InternetCheckConnectionA" (ByVal lpszUrl As String, ByVal dwFlags As Long, ByVal dwReserved As Long) As Long
Public Function isConnectInet()
isConnectInet = (InternetCheckConnection("http://www.baidu.com", &H1, 0&) <> 0)
End Function
Private Sub Form_Load()
If (InternetCheckConnection("http://www.baidu.com", &H1, 0&) <> 0) Then
Unload Me
Form2.Show
Else
Unload Me
Form3.Show
End If
End Sub
uj5u.com熱心網友回復:
獲得本地IP,是127.0.0.1則沒有連接。轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/153368.html
標籤:VB基礎類
上一篇:zedgraph 圖片保存
下一篇:用VB 如何進行并口通信?
