检查网络是否连接正常

<script src="win.js" type="text/javascript"></script>

头文件     WinInet.h    
静态库     WinInet.lib    

BOOL   InternetGetConnectedState(  
          OUT   LPDWORD   lpdwFlags,  
          IN     DWORD   dwReserved  
  );  

 

  DWORD   flags;//上网方式  
  BOOL     m_bOnline
//是否在线  
  m_bOnline=InternetGetConnectedState(&flags,0);  
  if(m_bOnline)//
在线  
  {  
          switch(&flags)  
          {  

          case   INTERNET_CONNECTION_MODEM   :  
                  AfxMessageBox("
在线:拨号上网");  
                  break;  
          case   INTERNET_CONNECTION_LAN   :  
                  AfxMessageBox("
在线:通过局域网");  
                  break;  
          case   INTERNET_CONNECTION_PROXY   :  
                  AfxMessageBox("
在线:代理");  
                  break;  
          }  
          if(&flags==INTERNET_CONNECTION_MODEM_BUSY)  
                  AfxMessageBox("MODEM
被其他非INTERNET连接占用");  
  }  
  else  
              AfxMessageBox("
不在线");

 

另外MSDN上有更多的解释:

Parameters  
   
  lpdwFlags    
  Address   of   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    
  Reserved.   Must   be   set   to   zero.    
  Return   Value  
   
  Returns   TRUE   if   there   is   an   Internet   connection,   or   FALSE   otherwise.  
   
  Function   Information  
   
  Windows   NT   Use   version   4.0.   Implemented   only   as   an   ANSI   function.    
  Windows   Use   Windows   95   and   later.   Implemented   only   as   an   ANSI   function.    
  Header   Wininet.h    
  Import   library   Wininet.lib    
  Minimum   availability   Internet   Explorer   4.0    
   
   
 
返回值中有个INTERNET_CONNECTION_OFFLINE   判断是不是离线的。  

 

 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值