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.
InternetGetConnectedStateEx()
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.
我用ADSL上网时,断开Internet时,它还返回true,为什么?
用ADSL时,它的第一个参数lpdwFlags会返回什么?
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用來判斷是否連接成功.
解决的办法是在InternetGetConnectedState前InternetAttemptConnect一下
但还有一个问题,当“电脑连上Internet”或“只是连接局域网”,这两种情况,能够编程去区别开吗?有没有相应的MFC或API函数?
btw abc_rain() is good.