vb6 get window title

Posted on 2006-03-25
Medium Priority
Last Modified: 2008-02-26
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...


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

Something like that...

Please help!
Question by:pugandjody
1 Comment
LVL 86

Accepted Solution

Mike Tomlinson earned 200 total points
ID: 16291109
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

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question