请问MFC/API中哪个函数能正确判断电脑连上Internet?
还有连上Internet/局域网时,电脑能作正确判断吗?它不会将连接上局域网,也认为是连上了Internbet了吧?

解决方案 »

  1.   

    API函数:
    InternetGetConnectedStateEx()
      

  2.   

    InternetGetConnectedState
    BOOL InternetGetConnectedState(
        OUT LPDWORD lpdwFlags,
        IN DWORD dwReserved
    );Retrieves the connected state of the local system. Returns TRUE if there is an Internet connection, FALSE otherwise. 
    lpdwFlags 
    Address of a double-word variable where the connection description should be returned. Can be a combination of the following values: INTERNET_CONNECTION_MODEM  Local system uses a modem to connect to the Internet. 
    INTERNET_CONNECTION_LAN  Local system uses a local area network to connect to the Internet. 
    INTERNET_CONNECTION_PROXY  Local system uses a proxy server to connect to the Internet. 
    INTERNET_CONNECTION_MODEM_BUSY  Local system's modem is busy with a non-Internet connection. dwReserved 
    Reserved. Must be set to zero. 
      

  3.   

    好象它检测不准哦?
    我用ADSL上网时,断开Internet时,它还返回true,为什么?
    用ADSL时,它的第一个参数lpdwFlags会返回什么?
      

  4.   

    CString strErrorMsg(_T("Connect internet failure!!"));
    DWORD dwFlags;
    if(InternetGetConnectedState(&dwFlags, 0)) 
    {
        if(dwFlags & INTERNET_CONNECTION_LAN ==   INTERNET_STATE_DISCONNECTED)
    {
    // Connect failure
    m_bOnline=FALSE;   
    AfxMessageBox(strErrorMsg, MB_OK | MB_ICONERROR); 
    return FALSE;
    }
    m_bOnline=TRUE;  
    }
    else
    {
    // Connect failure
    AfxMessageBox(strErrorMsg, MB_OK | MB_ICONERROR); 
    m_bOnline=FALSE;
    return FALSE;
    }
    m_bOnline用來判斷是否連接成功.
      

  5.   

    InternetGetConnectedState是根据系统当前接收的数据包,如果为零则反回INTERNET_STATE_DISCONNECTED,如果你ADSL一连接上,虽然已经连接internet,但没有收到任何数据,InternetGetConnectedState当然反回INTERNET_STATE_DISCONNECTED了。
    解决的办法是在InternetGetConnectedState前InternetAttemptConnect一下
      

  6.   

    多谢abc_rain和其它朋友们的回答!
    但还有一个问题,当“电脑连上Internet”或“只是连接局域网”,这两种情况,能够编程去区别开吗?有没有相应的MFC或API函数?
      

  7.   

    本来我也不清楚INTERNETGETCONNDECTEDSTATE(),现在明白了,多谢 abc_rain() 。
      

  8.   

    还有,使用InternetGetConnectedState(), InternetAttemptConnect()需要哪个头文件,或者DLL等?
      

  9.   

    WININET.H,
    btw abc_rain() is good.