PrivateSubForm_Load()
IfIsConnected=TRUEThen
MsgBox(“您已经连通了Internet!”)
EndIf
IfIsConnected=FALSEThen
MsgBox(“您还没有连通Internet!”)
EndIf
EndSub
OptionExplicit
/*有关的API声明和定义*/
PublicDeclareFunctionRasEnumConnectionsLib“RasApi32.dll”Alias“RasEnumConnectionsA”(lpRasConAsAny,lpcbAsLong,lpcConnectionsAsLong)AsLong
PublicDeclareFunctionRasGetConnectStatusLib“RasApi32.dll”Alias“RasGetConnectStatusA”(ByValhRasConAsLong,lpStatusAsAny)AsLong
/*常数和变量的设定*/
PublicConstRAS95_MaxEntryName=256
PublicConstRAS95_MaxDeviceType=16
PublicConstRAS95_MaxDeviceName=32
PublicTypeRASCONN95
dwSizeAsLong
hRasConAsLong
szEntryName(RAS95_MaxEntryName)AsByte
szDeviceType(RAS95_MaxDeviceType)AsByte
szDeviceName(RAS95_MaxDeviceName)AsByte
EndType
PublicTypeRASCONNSTATUS95
dwSizeAsLong
RasConnStateAsLong
dwErrorAsLong
szDeviceType(RAS95_MaxDeviceType)AsByte
szDeviceName(RAS95_MaxDeviceName)AsByte
EndType
/*函数IsConnected返回连通的状态,如果为True则表示已连通*/
PublicFunctionIsConnected()AsBoolean
DimTRasCon(255)AsRASCONN95
DimlgAsLong
DimlpconAsLong
DimRetValAsLong
DimTstatusAsRASCONNSTATUS95
TRasCon(0).dwSize=412
lg=256*TRasCon(0).dwSize
RetVal=RasEnumConnections(TRasCon(0),lg,lpcon)
IfRetVal<>0Then
MsgBox“错误”
ExitFunction
EndIf
Tstatus.dwSize=160
RetVal=RasGetConnectStatus(TRasCon(0)
.hRasCon,Tstatus)
IfTstatus.RasConnState=&H2000Then
IsConnected=TRUE
Else
IsConnected=FALSE
EndIf
EndFunction
IfIsConnected=TRUEThen
MsgBox(“您已经连通了Internet!”)
EndIf
IfIsConnected=FALSEThen
MsgBox(“您还没有连通Internet!”)
EndIf
EndSub
OptionExplicit
/*有关的API声明和定义*/
PublicDeclareFunctionRasEnumConnectionsLib“RasApi32.dll”Alias“RasEnumConnectionsA”(lpRasConAsAny,lpcbAsLong,lpcConnectionsAsLong)AsLong
PublicDeclareFunctionRasGetConnectStatusLib“RasApi32.dll”Alias“RasGetConnectStatusA”(ByValhRasConAsLong,lpStatusAsAny)AsLong
/*常数和变量的设定*/
PublicConstRAS95_MaxEntryName=256
PublicConstRAS95_MaxDeviceType=16
PublicConstRAS95_MaxDeviceName=32
PublicTypeRASCONN95
dwSizeAsLong
hRasConAsLong
szEntryName(RAS95_MaxEntryName)AsByte
szDeviceType(RAS95_MaxDeviceType)AsByte
szDeviceName(RAS95_MaxDeviceName)AsByte
EndType
PublicTypeRASCONNSTATUS95
dwSizeAsLong
RasConnStateAsLong
dwErrorAsLong
szDeviceType(RAS95_MaxDeviceType)AsByte
szDeviceName(RAS95_MaxDeviceName)AsByte
EndType
/*函数IsConnected返回连通的状态,如果为True则表示已连通*/
PublicFunctionIsConnected()AsBoolean
DimTRasCon(255)AsRASCONN95
DimlgAsLong
DimlpconAsLong
DimRetValAsLong
DimTstatusAsRASCONNSTATUS95
TRasCon(0).dwSize=412
lg=256*TRasCon(0).dwSize
RetVal=RasEnumConnections(TRasCon(0),lg,lpcon)
IfRetVal<>0Then
MsgBox“错误”
ExitFunction
EndIf
Tstatus.dwSize=160
RetVal=RasGetConnectStatus(TRasCon(0)
.hRasCon,Tstatus)
IfTstatus.RasConnState=&H2000Then
IsConnected=TRUE
Else
IsConnected=FALSE
EndIf
EndFunction
博客给出了检测Internet连接状态的代码。通过IsConnected函数判断是否连通,若连通弹出“您已经连通了Internet!”提示,未连通则弹出“您还没有连通Internet!”提示。代码中包含相关API声明、常数和变量设定。
522

被折叠的 条评论
为什么被折叠?



