怎样在程序里判断是否机器联入了internet?(20分)

  • 主题发起人 主题发起人 achang
  • 开始时间 开始时间
//判断当前是连上Internet的函数(uses WinInet)
function IsOnline:Boolean;
var
ConTypes : Integer;
begin
ConTypes := INTERNET_CONNECTION_MODEM + INTERNET_CONNECTION_LAN + INTERNET_CONNECTION_PROXY;
if (InternetGetConnectedState(@ConTypes, 0) = False)
then Result := False
else Result := True;
end;
 
INTERNET_CONNECTION_MODEM 哪的?
 
Uses部分加上WinInet
function CheckOffline: boolean;
var
ConnectState: DWORD;
StateSize: DWORD;
begin
ConnectState:= 0;
StateSize:= SizeOf(ConnectState);
result:= false;
if InternetQueryOption(nil, INTERNET_OPTION_CONNECTED_STATE, @ConnectState, StateSize) then
begin
if (ConnectState and INTERNET_STATE_DISCONNECTED) <> 2 then
begin
if InternetCheckConnection(nil, 1, 0) then
Result:=True;
end;
end;
end;
 
function CheckOffline: boolean;
var
ConnectState: DWORD;
StateSize: DWORD;
begin
ConnectState:= 0;
StateSize:= SizeOf(ConnectState);
result:= false;
if InternetQueryOption(nil, INTERNET_OPTION_CONNECTED_STATE, @ConnectState, StateSize) then
begin
if (ConnectState and INTERNET_STATE_DISCONNECTED) <> 2 then
begin
if InternetCheckConnection(nil, 1, 0) then
begin
Result:=True;
showmessage('on line!');
end
else
begin
showmessage('not on line!');
end;
end;
end;
end;
 
我倒!呵呵:)
 
好像ADSL不支持吧

 
to yhm8你试试就知道了!:)
 
to achang 下面是修正函数!应该可以判断所以类型了!
//判断当前是连上Internet的函数(uses WinInet)
uses WinInet
……
function IsOnline:Boolean;
var
ConTypes : Integer;
begin
ConTypes := INTERNET_CONNECTION_MODEM + INTERNET_CONNECTION_LAN +
INTERNET_CONNECTION_PROXY+INTERNET_CONNECTION_MODEM_BUSY;
if (InternetGetConnectedState(@ConTypes, 0) = False)
then Result := False
else Result := True;
end;
 
后退
顶部