Jump to content

Bring Firefox to front


Recommended Posts

Didn't think of that KaFu, thanks.

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

#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

Link to comment
Share on other sites

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

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

  • 11 months later...

&nbsp;

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.

Link to comment
Share on other sites

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
Link to comment
Share on other sites

  • 4 months later...

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
Link to comment
Share on other sites

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!

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

Link to comment
Share on other sites

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.

 

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.

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

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