Jump to content

Recommended Posts

Posted

Didn't think of that KaFu, thanks.

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Posted

  On 1/12/2013 at 11:33 PM, 'KaFu said:

#include <array.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>

$aHwnds_Firefox = WinList("[CLASS:MozillaWindowClass]")
_ArrayDisplay($aHwnds_Firefox)

$hWnd = WinGetHandle('[CLASS:MozillaWindowClass]')
$hWnd_RootOwner = _WinAPI_GetAncestor($hWnd, $GA_ROOTOWNER)
WinActivate($hWnd_RootOwner)

That totally solved the problem. This is great.

Thank you very very much. I've been working on this for a long time. This fixed it.

Thank you,

Docfxit

Posted

Great. Next time I will remember to ask the OP if they've checked the root owner. Firefox is strange.

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

  • 11 months later...
Posted

&nbsp;

  On 1/17/2013 at 7:25 PM, Docfxit said:

That totally solved the problem. This is great.

Thank you very very much. I've been working on this for a long time. This fixed it.

Thank you,

Docfxit

&nbsp;

I've just tried the same thing, using KaFu's code. But it doesn't bring Firefox to the front. I just get an array that appears to be a list of Firefox tabs, i think.

Posted (edited)

I've added the _ArrayDisplay() only to demonstrate that Firefox has several windows and you need to identify the right one you want to bring to the front... strangely enough, this code does not work for me now too, I've used it successfully on Win7, now on Win8 it does not bring FF to the front :ermm:... but this one does.

$aHwnds_Firefox = WinList("[CLASS:MozillaWindowClass]")
For $i = 1 to $aHwnds_Firefox[0][0]
    if $aHwnds_Firefox[$i][1] then WinActivate($aHwnds_Firefox[$i][0])
Next
Edited by KaFu
  • 4 months later...
Posted (edited)

Just check the title:

; Johnmcloud - 2014
If Not ProcessExists("firefox.exe") Then Exit
$hFirefox = WinGetHandle("[REGEXPTITLE:(?i)(.* - Mozilla Firefox);CLASS:MozillaWindowClass]")
ConsoleWrite("HANDLE: " & $hFirefox & @CRLF)
WinActivate($hFirefox)

Or if you want to use the KaFu version:

WinList("[REGEXPTITLE:(?i)(.* - Mozilla Firefox);CLASS:MozillaWindowClass]")
Edited by johnmcloud
Posted
  On 5/18/2014 at 2:11 AM, VAN0 said:

The problem with using [CLASS:MozillaWindowClass], is that Firefox is not the only program that has this class. Anything Mozilla made could be affected http://www.mozilla.org/about/mozilla-based/ At least Thunderbird does.

That's a normal "problem" with any window that you're accessing by the class. Just because there are sometimes going to be numerous windows sharing the same class doesn't mean it's not the right way to do it. Supposing you were trying to access a notepad window, occasionally you're going to have more than one open at a time. Your code needs to make sure you're talking to the right one.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

  Reveal hidden contents

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Posted

  On 5/18/2014 at 5:55 PM, johnmcloud said:

Just check the title:

; Johnmcloud - 2014
If Not ProcessExists("firefox.exe") Then Exit
$hFirefox = WinGetHandle("[REGEXPTITLE:(?i)(.* - Mozilla Firefox);CLASS:MozillaWindowClass]")
ConsoleWrite("HANDLE: " & $hFirefox & @CRLF)
WinActivate($hFirefox)
Or if you want to use the KaFu version:

WinList("[REGEXPTITLE:(?i)(.* - Mozilla Firefox);CLASS:MozillaWindowClass]")

When it comes to Firefox this method is also not 100% proof. For example I don't have anything that says it's Firefox in my Firefox' title. I use extension that allows me to change it.

 

  On 5/18/2014 at 6:19 PM, BrewManNH said:

That's a normal "problem" with any window that you're accessing by the class. Just because there are sometimes going to be numerous windows sharing the same class doesn't mean it's not the right way to do it. Supposing you were trying to access a notepad window, occasionally you're going to have more than one open at a time. Your code needs to make sure you're talking to the right one.

By no means I meant to sound like this was a wrong way to do it. I just pointed out, that in case of Firefox this method is not 100% working...

If I have a full path to firefox.exe how would get list of all processes or threads or windows this process has? Perhaps we could go from this direction.

Posted (edited)

Like this?

; Johnmcloud - 2014
Local $PID

Local $aFirefox = ProcessList("firefox.exe")
For $i = 1 To $aFirefox[0][0]
    $PID = $aFirefox[$i][1]
    ExitLoop
Next

;~ Original post by Kafu
Local $aHwnds_Firefox = WinList("[CLASS:MozillaWindowClass]")
For $i = 1 To $aHwnds_Firefox[0][0]
    If $aHwnds_Firefox[$i][0] <> "" Then
        ConsoleWrite("TITLE: " & $aHwnds_Firefox[$i][0] & @CRLF)
        ConsoleWrite("HANDLE: " & $aHwnds_Firefox[$i][1] & @CRLF)
        If $aHwnds_Firefox[$i][1] And WinGetProcess($aHwnds_Firefox[$i][1]) = $PID Then
            WinActivate($aHwnds_Firefox[$i][0])
        EndIf
    EndIf
Next

Obv is there are more then one process with different PIDs you need to create an array of PIDs and check that array in loop with WinGetProcess

Edited by johnmcloud
Posted (edited)

That works much better, doesn't conflict with Thunderbird. Thanks.

But what if you don't know the class, if you only have PID and/or HWND, path to .exe? Just use empty WinList() ?

Edited by VAN0

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...