VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Get Active window caption and work on active window

by Kailash Chandra Vaishnav (1 Submission)
Category: Custom Controls/Forms/Menus
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Sat 25th June 2011
Date Added: Mon 8th February 2021
Rating: (1 Votes)

Get Active window caption and work on active window

API Declarations


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 Declare Function GetParent Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function SetActiveWindow Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function GetActiveWindow Lib "user32" () As Long


Rate Get Active window caption and work on active window



Public Function GetActiveWindowTitle(ByVal ReturnParent As Boolean) As String
    Dim i As Long
    Dim j As Long
    i = GetForegroundWindow
    If ReturnParent Then
    Do While i <> 0
    j = i
    i = GetParent(i)
    Loop
    i = j
    End If
    GetActiveWindowTitle = GetWindowTitle(i)
End Function
Public Function GetWindowTitle(ByVal hwnd As Long) As String
Dim l As Long
Dim s As String
l = GetWindowTextLength(hwnd)
s = Space(l + 1)

GetWindowText hwnd, s, l + 1

GetWindowTitle = Left$(s, l)
End Function

Private Sub Timer1_Timer()
Print GetActiveWindowTitle(GetActiveWindow)
If Trim(GetActiveWindowTitle(GetActiveWindow)) = "Yahoo" Then
    X = SetActiveWindow(i)
    SendKeys ("%{S}")
End If
If Trim(GetActiveWindowTitle(GetActiveWindow)) = "Save As" Then
    X = SetActiveWindow(i)
    Clipboard.SetText "D:\kc.txt"
    SendKeys ("%{N}")
    SendKeys ("^{V}")
    SendKeys ("{TAB}")
    SendKeys ("{TAB}")
    Timer1.Interval = 0
End If
End Sub


Download this snippet    Add to My Saved Code

Get Active window caption and work on active window Comments

No comments have been posted about Get Active window caption and work on active window. Why not be the first to post a comment about Get Active window caption and work on active window.

Post your comment

Subject:
Message:
0/1000 characters