Results 1 to 8 of 8

Thread: [RESOLVED] how would you uses FindWindow like this?

  1. #1

    Thread Starter
    Fanatic Member newprogram's Avatar
    Join Date
    Apr 2006
    Location
    in your basement
    Posts
    769

    Resolved [RESOLVED] how would you uses FindWindow like this?

    how would I do a instr for this, the caption changes but at the beginning there also this "Timery" so it how would I find it i tried


    lhWnd = InStr(FindWindow, vbNullString, "Timery")

    Code:
    Dim lhWnd As Long
    Do
     lhWnd = FindWindow(vbNullString, "Timery")
    If lhWnd Then
    MsgBox "it here"
    End If
    
    Loop While lhWnd
    Last edited by newprogram; Feb 2nd, 2009 at 07:04 PM.
    Live life to the fullest!!

  2. #2
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: how would you uses FindWindow like this?

    I don't think you can do that with FindWindow. How about using EnumWindows API?
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  3. #3
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    4,255

    Re: how would you uses FindWindow like this?

    Here's a way to use the "*" character as a wild card to get handles of windows by passing a partial title and class name.

    Code:
    Option Explicit
    Private WinHwnd(512) As Long
    Private WindCnt As Integer
    Private Const GW_CHILD = 5
    Private Const GW_HWNDNEXT = 2
    Private Declare Function GetParent Lib "user32" (ByVal hwnd As Long) As Long
    Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As Any, ByVal lpWindowName As Any) As Long
    Private Declare Function GetDesktopWindow Lib "user32" () As Long
    Private Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd 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 GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
    
    Private Function FindWindowLike(ByVal hWndStart As Long, WindowText As String, Classname As String) As Long
        Dim hwnd As Long
        Dim sWindowText As String
        Dim sClassname As String
        Dim r As Long
        Static level As Integer
        If level = 0 Then
           If hWndStart = 0 Then hWndStart = GetDesktopWindow()
        End If
        level = level + 1
        hwnd = GetWindow(hWndStart, GW_CHILD)
        Do Until hwnd = 0
            Call FindWindowLike(hwnd, WindowText, Classname)
            sWindowText = Space$(255)
            r = GetWindowText(hwnd, sWindowText, 255)
            sWindowText = Left(sWindowText, r)
            sClassname = Space$(255)
            r = GetClassName(hwnd, sClassname, 255)
            sClassname = Left(sClassname, r)
            If (sWindowText Like WindowText) And (sClassname Like Classname) Then
                    WinHwnd(WindCnt) = hwnd
                    WindCnt = WindCnt + 1
            End If
          hwnd = GetWindow(hwnd, GW_HWNDNEXT)
        Loop
      level = level - 1
    End Function
    
    Private Sub Command1_Click()
        
        Dim i As Integer
        Erase WinHwnd()
        WindCnt = 0 ' reset counter
    
    
        ' use "*" as wild card before and after classname and title as needed.
        ' strings are case sensitve!
        
        ' find all open programs with title bar that includes "VBForums"
        FindWindowLike 0, "*VBForums*", "*"  ' start hwnd, titlebar, classname
        
        For i = 0 To WindCnt - 1
            Debug.Print WinHwnd(i) ' show all handles found
        Next i
        
    End Sub
    Last edited by Edgemeal; Feb 2nd, 2009 at 07:20 PM. Reason: updated

  4. #4
    Frenzied Member some1uk03's Avatar
    Join Date
    Jun 2006
    Location
    London, UK
    Posts
    1,675

    Re: how would you uses FindWindow like this?

    Have a look at this
    _____________________________________________________________________

    ----If this post has helped you. Please take time to Rate it.
    ----If you've solved your problem, then please mark it as RESOLVED from Thread Tools.



  5. #5

    Thread Starter
    Fanatic Member newprogram's Avatar
    Join Date
    Apr 2006
    Location
    in your basement
    Posts
    769

    Re: how would you uses FindWindow like this?

    thank you . Edgemeal that work great!!
    Live life to the fullest!!

  6. #6
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: [RESOLVED] how would you uses FindWindow like this?

    How about this?

    Code:
    Option Explicit
    
    Private Sub Form_Load()
        EnumWindows AddressOf EnumWindowsProc, ByVal 0&
    End Sub
    In a module
    Code:
    Option Explicit
    
    Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Boolean
    Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
    Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long
    
    Public Function EnumWindowsProc(ByVal hwnd As Long, ByVal lParam As Long) As Boolean
        Dim sWindowText As String
        Dim Ret         As Long
        
        Ret = GetWindowTextLength(hwnd)
        sWindowText = Space(Ret)
        GetWindowText hwnd, sWindowText, Ret + 1
        If Ret > 0 Then
            If sWindowText Like "Projec*" Then
                Debug.Print sWindowText
            End If
        End If
        EnumWindowsProc = True
    End Function
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  7. #7

    Thread Starter
    Fanatic Member newprogram's Avatar
    Join Date
    Apr 2006
    Location
    in your basement
    Posts
    769

    Re: [RESOLVED] how would you uses FindWindow like this?

    that work even better thank you!!
    Quote Originally Posted by dee-u
    How about this?

    Code:
    Option Explicit
    
    Private Sub Form_Load()
        EnumWindows AddressOf EnumWindowsProc, ByVal 0&
    End Sub
    In a module
    Code:
    Option Explicit
    
    Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Boolean
    Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
    Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long
    
    Public Function EnumWindowsProc(ByVal hwnd As Long, ByVal lParam As Long) As Boolean
        Dim sWindowText As String
        Dim Ret         As Long
        
        Ret = GetWindowTextLength(hwnd)
        sWindowText = Space(Ret)
        GetWindowText hwnd, sWindowText, Ret + 1
        If Ret > 0 Then
            If sWindowText Like "Projec*" Then
                Debug.Print sWindowText
            End If
        End If
        EnumWindowsProc = True
    End Function
    Live life to the fullest!!

  8. #8
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    4,255

    Re: [RESOLVED] how would you uses FindWindow like this?

    Quote Originally Posted by newprogram
    that work even better thank you!!
    But you can't enter a classname, so it does have some drawbacks.
    (dee-u hint hint )

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