ICQ NetDetect

 ICQ (I Seek You) have a program called NetDetect that stays in the system tray until a internet connection is detected. When this happens, it closes itself and launch ICQ main program.
  My question is: To implement the same funcionality of NetDetect I should keep checking for internet connection (via wininet API) or there is a more efficient way to do this?
felipesAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
MicheltConnect With a Mentor Commented:
Add this code to the module:

Public Const ERROR_SUCCESS = 0&
Public Const APINULL = 0&
Public Const HKEY_LOCAL_MACHINE = &H80000002
Public ReturnCode As Long

Declare Function RegCloseKey Lib "advapi32.dll" (ByVal _
hKey As Long) As Long

Declare Function RegOpenKey Lib "advapi32.dll" Alias _
"RegOpenKeyA" (ByVal hKey As Long, ByVal lpSubKey As _
String, phkResult As Long) As Long

Declare Function RegQueryValueEx Lib "advapi32.dll" Alias _
"RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName _
As String, ByVal lpReserved As Long, lpType As Long, _
lpData As Any, lpcbData As Long) As Long

Public Function ActiveConnection() As Boolean
Dim hKey As Long
Dim lpSubKey As String
Dim phkResult As Long
Dim lpValueName As String
Dim lpReserved As Long
Dim lpType As Long
Dim lpData As Long
Dim lpcbData As Long
ActiveConnection = False
lpSubKey = "System\CurrentControlSet\Services\RemoteAccess"
ReturnCode = RegOpenKey(HKEY_LOCAL_MACHINE, lpSubKey, _
phkResult)

If ReturnCode = ERROR_SUCCESS Then
hKey = phkResult
lpValueName = "Remote Connection"
lpReserved = APINULL
lpType = APINULL
lpData = APINULL
lpcbData = APINULL
ReturnCode = RegQueryValueEx(hKey, lpValueName, _
lpReserved, lpType, ByVal lpData, lpcbData)
lpcbData = Len(lpData)
ReturnCode = RegQueryValueEx(hKey, lpValueName, _
lpReserved, lpType, lpData, lpcbData)

If ReturnCode = ERROR_SUCCESS Then
If lpData = 0 Then
ActiveConnection = False
Else
ActiveConnection = True
End If
End If

RegCloseKey (hKey)
End If

End Function

Add this code to the form:

Private Sub check_connect()
If ActiveConnection = True Then
  check_connect = true
Else
   check_connect = false
End If
End Sub

Private sub Formload
 pause
end sub

Private Sub Pause()

Dim PauseTime, Start, Finish, TotalTime
Dim bConnect as boolean

Do While bconnect = False
    xtim = xtim + 1
    PauseTime = 5
    Start = Timer
    Do While Timer < Start + PauseTime
       DoEvents
    Loop
    Finish = Timer
    TotalTime = Finish - Start
    bconnect = check_connect
loop

end sub

If you have problems using the code the please e-mail me.

0
 
thegilbCommented:
The only way I can think of doing this is having a timer... I mean - NetDetect I think works the same way by just sticking a timer up and giving it a delay of 5000 I think... Not too sure... Give the timer a try and lemme know how it goes...
0
 
eduncCommented:
i don't have an answer to your question, but can you give me your code of how you check for an internet connection?  my email is unc69jz@hotpop.com   thanks.
0
 
MirkwoodCommented:
Bought This Question.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.