Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1634
  • Last Modified:

Get firefox's handle

FindWindow("MozillaUIWindowClass", vbNullString)

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

i just need firefox's handle.

How can i get one??

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

Check it out

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.
HFunakawaAuthor Commented:
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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now