精华区 [关闭][返回]

当前位置:网易精华区>>讨论区精华>>编程开发>>● VB和Basic>>〓〓..API 函数使用..〓〓>>网络相关>>监视Internet连接

主题:监视Internet连接
发信人: plindge()
整理人: winsy(2003-03-05 15:42:47), 站内信件
【 在 punkfan (ufo) 的大作中提到: 】
: vb中如何监视连接?如未连接如何像IE或吸血鬼一样自动要求连接

: 请教,谢谢,谢谢。
[email protected]
:    .......

用一个timer时刻检测连接
If IsConnected = True Then
'StatusTxt.Caption = "您已经连接到Internet了!"
else
call dial
end if
sub dial()
Dim X
X = Shell("rundll32.exe rnaui.dll,RnaDial " & "163", 1)
DoEvents
SendKeys "{enter}", True
DoEvents

' 163为拨号网络里的连接
’如果有多个连接也可通过API取得RAS的名称

'modem.bas 检查是否连接
Option Explicit

Public Declare Function RasEnumConnections Lib "RasApi32.dll" Alias "R
asEnumConnectionsA" (lpRasCon As Any, lpcb As Long, lpcConnections As 
Long) As Long
Public Declare Function RasGetConnectStatus Lib "RasApi32.dll" Alias "
RasGetConnectStatusA" (ByVal hRasCon As Long, lpStatus As Any) As Long

'
Public Const RAS95_MaxEntryName = 256
Public Const RAS95_MaxDeviceType = 16
Public Const RAS95_MaxDeviceName = 32
'
Public Type RASCONN95
    dwSize As Long
    hRasCon As Long
    szEntryName(RAS95_MaxEntryName) As Byte
    szDeviceType(RAS95_MaxDeviceType) As Byte
    szDeviceName(RAS95_MaxDeviceName) As Byte
End Type
'
Public Type RASCONNSTATUS95
    dwSize As Long
    RasConnState As Long
    dwError As Long
    szDeviceType(RAS95_MaxDeviceType) As Byte
    szDeviceName(RAS95_MaxDeviceName) As Byte
End Type
        


Public Function IsConnected() As Boolean
Dim TRasCon(255) As RASCONN95
Dim lg As Long
Dim lpcon As Long
Dim RetVal As Long
Dim Tstatus As RASCONNSTATUS95
'
TRasCon(0).dwSize = 412
lg = 256 * TRasCon(0).dwSize
'
RetVal = RasEnumConnections(TRasCon(0), lg, lpcon)
If RetVal <> 0 Then
                    MsgBox "ERROR"
                    Exit Function
                    End If
'
Tstatus.dwSize = 160
RetVal = RasGetConnectStatus(TRasCon(0).hRasCon, Tstatus)
If Tstatus.RasConnState = &H2000 Then
                         IsConnected = True
                         Else
                         IsConnected = False
                         End If

End Function


--
---欢迎光临品琳居---
一个情感交流与编程交流的清幽小居!
大量VB源程序、VFP商用源程序供下载!
Http://plindge.163.net
Http://plindge.yeah.net
---欢迎光临品琳居---

※ 来源:.月光软件站 http://www.moon-soft.com.[FROM: 202.103.139.59]

[关闭][返回]