Results 1 to 2 of 2

Thread: Search for Window Handle

  1. #1
    assbeef
    Guest

    Search for Window Handle

    I need code to search for a piece of a window's handle, and if found, it will destroy that window. I have code that does this but you must supply the entire handle and case sensitive. Is there any way of only using part of the window's handle? An example would be to destroy IE, or Netscape or whatever multi-form application.

    Thanks

  2. #2
    Megatron
    Guest
    Use the EnumWindows function.
    VB Code:
    1. 'Add to a Module
    2. Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
    3. Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long
    4. Declare Function EnumWindows Lib "user32.dll" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
    5.  
    6. Public Function EnumWindowsProc(ByVal hwnd As Long, ByVal lParam As Long) As Long
    7.     Dim Length As Long
    8.     Dim sName As String
    9.     Dim Temp As String
    10.     Static iCount As Integer
    11.    
    12.     iCount = iCount + 1
    13.     Length = GetWindowTextLength(hwnd) + 1
    14.    
    15.     If Length > 1 Then
    16.       sName = Space(Length)
    17.       GetWindowText hwnd, sName, Length
    18.       sName = Left(sName, Length - 1)
    19.       If sName Like "*My Title Fragment*" Then MsgBox "Window Found!"
    20.     End If
    21.    
    22.     EnumWindowsProc = 1
    23. End Function
    24.  
    25. 'Usage:
    26. EnumWindows AddressOf EnumWindowsProc, 0

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