Get firefox's handle

Posted on 2009-04-27
Last Modified: 2013-12-07

FindWindow("MozillaUIWindowClass", vbNullString)

using spy+
Firefox and Thunderbird have same class name "MozillaUIWindowClass"

i just need firefox's handle.

How can i get one??

Question by:HFunakawa
    LVL 6

    Expert Comment

    I have used this program to do checkings on windows handle ID every 10 minutes.

    Check it out
    LVL 1

    Accepted Solution

    You could possibly try to create a loop similar to the following:

    Dim found as Boolean=False
    Dim hMozilla as Integer=-1
    Dim strWinTitle as String
    Dim firstRun as Boolean = True
    While hMozilla<>0 and found=False

       if firstRun = True then
          hMozilla=FindWindowEx(NULL, NULL, "MozillaUIWindowClass", NULL)
          firstRun = False
          hMozilla=FindWindowEx(NULL, hMozilla, "MozillaUIWindowClass", NULL)
       end if

       if hMozilla<>0 then
          Dim length as Integer = GetWindowTextLength(hMozilla)
          Dim sb as New System.Text.StringBuilder(ChrW(0), length + 1)
          strWinTitle = GetWindowText(hMozilla, sb, sb.Capacity)
          if instr(strWinTitle, "Mozilla Firefox") <> 0 then found = True
       end if
    End While

    Note that you will have to add the following declarations (including FindWindowEx instead of FindWindow):

    Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hWnd As IntPtr, _
                                                                            <Out()> ByVal lpString As System.Text.StringBuilder, _
                                                                            ByVal cch As Integer) As Integer
    Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hWnd As IntPtr) As Integer

    Declare Function FindWindowEx Lib "user32.dll" Alias "FindWindowExA" (ByVal hWndParent as IntPtr, ByVal hWndChildAfter as IntPtr, ByVal lpClassName as String, ByVal lpWindowName as String) as Integer

    The above code should step through each window, retrieve the title, search for the phrase "Mozilla Firefox", and if found, the variable hMozilla will hold the handle of the window you are looking for.  Pardon me if I have made any coding errors in the above sample.  I am currently using a computer with no Visual Basic, so I can't test this code, but I believe the concept is correct.

    Author Comment

    it is very interesting.
    thank you!

    thank you for code help.
    it works perfectly.

    one small change
      instr(sb.tostring, "Mozilla Firefox") <> 0

    thanks once again!!


    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Suggested Solutions

    I recently found myself in a Corporate Situation where the client had requested blocking access to any and all websites except his own Domain? Easy? I am sure this would be your answer but their requirement was, this has to be done without using…
    Several part series to implement Internet Explorer 11 Enterprise Mode
    Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
    Google currently has a new report that is in beta and coming soon to Webmaster Tool accounts. This Micro Tutorial will highlight new features for Google Webmaster Tools.

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now