CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: FindWindow

  1. #1
    Join Date
    Jun 2001
    Posts
    4

    FindWindow

    Hi, i have used FindWindow API to detect if mIRC is running. all goes well until i minimized it and it started flashing because i had a message. Then i noticed that the mirc caption had changed to 'mIRC32 [message]'. Now my program cannot find it because i told it to look for 'mIRC32'

    How can i get around this? is there a way i can check for just the left four character 'mirc'?


  2. #2
    Join Date
    Jun 2001
    Location
    Israel
    Posts
    228

    Re: FindWindow

    there are 2 parameters to FindWindow :
    lpClassName & lpWindowName, you probably use lpWindowName and when the caption changes you cannot find the window. lpClassName is exactly what you need, that is if a certain app is running.
    you should find the classname of mirc (it may even be mIRC) by trying to think what the name of the app (class) may be. if you want to check it out you can try it on Notepad, if i'm not mistaken it's class name is "Notepad"

    ----------
    The @host is everywhere!
    ----------

  3. #3
    Join Date
    Jan 2001
    Posts
    165

    Re: FindWindow

    A better way to get the class name is to use Spy++. Just start the mIRC application and run Spy++ to view all the information that you will need.

    Another solution to your problem may be to enumerate all the windows open on your system and then iterate over the names and perform your own Window Name matching. This way you can match only the left 4 characters if you would like. Though using the class name is probably the fastest way.

    -K


  4. #4
    Join Date
    May 2000
    Location
    New York, NY, USA
    Posts
    2,878

    Re: FindWindow

    You can find window by part of it caption, using wild cards

    '---Bas module code------


    Private Declare Function EnumWindows& Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam 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 IsWindowVisible& Lib "user32" (ByVal hwnd As Long)
    Private Declare Function GetParent& Lib "user32" (ByVal hwnd As Long)
    Dim sPattern As String, hFind As Long


    Function EnumWinProc(ByVal hwnd As Long, ByVal lParam As Long) As Long
    Dim k As Long, sName As String


    If IsWindowVisible(hwnd) And GetParent(hwnd) = 0 Then
    sName = Space$(128)
    k = GetWindowText(hwnd, sName, 128)


    If k > 0 Then
    sName = Left$(sName, k)
    If lParam = 0 Then sName = UCase(sName)


    If sName Like sPattern Then
    hFind = hwnd


    EnumWinProc = 0
    Exit Function
    End If
    End If
    End If


    EnumWinProc = 1
    End Function


    Public Function FindWindowWild(sWild As String, Optional bMatchCase As Boolean = True) As Long
    sPattern = sWild
    If Not bMatchCase Then sPattern = UCase(sPattern)


    EnumWindows AddressOf EnumWinProc, bMatchCase
    FindWindowWild = hFind
    End Function


    '----Using (Form code)----


    Private Sub Command1_Click()
    Debug.Print FindWindowWild("*Mi??OSoFt In[s-u]ernet*", False)
    End Sub



    Iouri Boutchkine
    [email protected]
    Iouri Boutchkine
    [email protected]

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

Featured