Need to determine modem connect speed

How can I detect the current modem connection speed in VB?
(After DUN connnection has been established)
rmarshlAsked:
Who is Participating?
 
KDivadConnect With a Mentor Commented:
I'm sure that there is a "correct" way to do this, but this code will retreive the speed.

Paste into any module's declaration section.

Private Const GW_HWNDNEXT = 2
Private Const GW_CHILD = 5

Private Declare Function GetWindow Lib "user32" Alias "GetWindow" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Private Declare Function GetDesktopWindow Lib "user32" Alias "GetDesktopWindow" () As Long

Public Function ConnectAt() As Long
   
    Dim T_hWnd As Long
    Dim CT_hWnd As Long
    Dim WText As String
    T_hWnd = GetWindow(GetDesktopWindow, GW_CHILD)
    Do Until T_hWnd = 0
        WText = Space$(255)
        RetVal = GetWindowText(T_hWnd, WText, 255)
        If Left$(WText, 13) = "Connected to " Then
            CT_hWnd = GetWindow(T_hWnd, GW_CHILD)
            Do Until CT_hWnd = 0
                WText = Space$(255)
                RetVal = GetWindowText(CT_hWnd, WText, 255)
                If Left$(WText, 13) = "Connected at " Then
                    WText = Right$(WText, Len(WText) - 13)
                    Do
                        x = InStr(x + 1, WText, ",")
                        If x > 0 Then
                            WText = Left$(WText, x - 1) & Right$(WText, Len(WText) - x)
                        Else
                            Exit Do
                        End If
                    Loop
                    ConnectAt = Val(WText)
                    Exit Function
                End If
                CT_hWnd = GetWindow(CT_hWnd, GW_HWNDNEXT)
            Loop
        End If
        T_hWnd = GetWindow(T_hWnd, GW_HWNDNEXT)
    Loop

End Function


Call using:
MyConnectionSpeed = ConnectAt

Hope this helps!
0
 
KDivadCommented:
You can get it from the DUN Window itself by searching (using FindWindow)for it's hWnd. It's class is "#32770". You can check the caption of all Windows having this class for one starting with "Connected to ". This should be the DUN Window. Then search it's children for a control of class "Static" that has a caption starting with "Connected at ". This child control's caption will contain the connection speed.
0
 
rmarshlAuthor Commented:
My version of VB 6.0 does not seem to have a "FindWindow" command.

0
 
KDivadCommented:
FindWindow is an API. The declare (for a .bas module) is:

Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long

You can use:

hWnd = FindWindow("#32770", vbNullString)

to find a window, however, it returns the first one it comes across.

Give me a few minutes and I'll draw up some actual code for you.
0
All Courses

From novice to tech pro — start learning today.