vb6 get window title

I'm trying to write a vb6 program with a timer.

Basically every few minutes a timer would check and see if the top window that is opended has a certain title then if it does then send the enter key...

(eg.



Private Sub Timer1_Timer()
 IF top window.title = "Register StationRipper" THEN SendKeys("ENTER")
End Sub

Something like that...

Please help!
pugandjodyAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mike TomlinsonHigh School Computer Science, Computer Applications, and Mathematics TeachersCommented:
Something like...

Option Explicit

Private Declare Function GetForegroundWindow Lib "user32" () As Long
Private Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd 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 Sub Timer1_Timer()
    If GetCurrentWindowText() = "Register StationRipper" Then
        SendKeys "{Enter}"
    End If
End Sub

Private Function GetCurrentWindowText() As String
    Dim foreWnd As Long
    foreWnd = GetForegroundWindow()
    GetCurrentWindowText = String(GetWindowTextLength(foreWnd) + 1, Chr$(0))
    GetWindowText foreWnd, GetCurrentWindowText, Len(GetCurrentWindowText)
End Function

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.