• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1258
  • Last Modified:

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!
0
pugandjody
Asked:
pugandjody
1 Solution
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
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
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.

Join & Write a Comment

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now