Results 1 to 2 of 2

Thread: Active Window

  1. #1

    Thread Starter
    Hyperactive Member zer0_flaw's Avatar
    Join Date
    Apr 2001
    Posts
    448

    Active Window

    If I press a command button (Command1), I want a message box for EVERY program (other then mine) I click on to display that program's caption. How can I do this? Any help would be GREATLY appreciated. Thanks in advance. Later,

    -zer0 flaw

  2. #2
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527

    <¿>

    ?

    VB Code:
    1. Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
    2. Private Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long
    3. Private Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Long, ByVal yPoint As Long) As Long
    4. Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
    5. Private Type POINTAPI
    6.     x As Long
    7.     y As Long
    8. End Type
    9. Dim textlen As Long  ' receives length of text of the window
    10. Dim wintext As String  ' receives the text of the window
    11. Dim slength As Long  ' receives the length of the returned string
    12. Dim myhWnd As Long
    13. Dim mousePos As POINTAPI
    14.  
    15. Private Sub Timer1_Timer()
    16. ' Every 10 seconds get the title of the window which the cursor is over
    17. ' Find out how many characters are in the window's text.
    18. ' Add 1 to compensate for the terminating null.
    19. retval = GetCursorPos(mousePos)
    20. myhWnd = WindowFromPoint(mousePos.x, mousePos.y)
    21. Debug.Print myhWnd
    22. textlen = GetWindowTextLength(myhWnd) + 1
    23. ' Make sufficient room in the buffer.
    24. wintext = Space(textlen)
    25. ' Retrieve the text of window Form1.
    26. slength = GetWindowText(myhWnd, wintext, textlen)
    27. ' Remove the empty space from the string, if any.
    28. Text1.Text = Text1 & vbCrLf & Left(wintext, slength)
    29.  
    30. ' Display the result.
    31. End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width