Jump to content
Sign in to follow this  
FMS

WinWait whit same title and text

Recommended Posts

Hello,

I'm having a problem whit winwait on firefoxscreens whit the same title and text.
On mine quest on this forum and internet I've found some work around and solutions.
unfortunaly This wasn't working for me.

I've tried searching tru winlist or finding some unique text but wasn't finding any solution.
Does anyone know how to get the wright handle?
I just want to move the browser to the right place in the end whit WinMove.

thnx in advanced.

 

#include <Array.au3>
Global $A_URL[4][2] =  _
      [["url1" , "same_title"] , _
      ["url2", "same_title"] , _
      ["url3" , "other_title" ] , _
      ["url4" , "other_title" ]]
;~ _ArrayDisplay($A_URL)

;-----kill all firefox.exe
;~ Run("taskkill /IM firefox.exe /F", "", @SW_HIDE)
;Sleep(5000)

For $i = 0 To 1
   ConsoleWrite("running 1 : " & $i & @CRLF)
   Local $ID = ShellExecute("firefox.exe", "-new-window " & $A_URL[$i][0] ,"C:\Program Files\Mozilla Firefox" )
   ConsoleWrite("$ID = " & $ID & @CRLF)
Next
sleep(200)
;~    Local $screen1HWND = WinWait($A_URL[0][1],"")
;~    If Not WinActive($screen1HWND) Then WinActivate($screen1HWND)
;~    ConsoleWrite("$screen1HWND = " & $screen1HWND & @CRLF)
;~    Local $screen2HWND = WinWait($A_URL[1][1],"")
;~    If Not WinActive($screen2HWND) Then WinActivate($screen2HWND)
;~    ConsoleWrite("$screen2HWND = " & $screen2HWND & @CRLF)
$sWinTitle = $A_URL[0][1]
$avWinList = WinList($sWinTitle)
For $n = 1 to $avWinList[0][0]
    ConsoleWrite("Window " & $n & ":  Text:  " & WinGetText($avWinList[$n][1]) & @LF)
Next

For $i = 0 To 1
;~    WinWait("title1", "", 10)
;~    WinActive("title1", "")
;~    WinMove ("title1", "", $i , $i )
Next

 


as finishing touch god created the dutch

Share this post


Link to post
Share on other sites
16 minutes ago, FMS said:

Does anyone know how to get the wright handle?
I just want to move the browser to the right place in the end whit WinMove.

 

But witch is the right window if these are of the same Title and Text? Witch of the two browser windows do you want to move?


Rule #1: Always do a backup         Rule #2: Always do a backup (backup of rule #1)

Share this post


Link to post
Share on other sites

both :)
the first i want to move to place 1 and the other to another place on the screen.


as finishing touch god created the dutch

Share this post


Link to post
Share on other sites
#include <Array.au3>
Global $A_URL[4][2] =  _
      [["www.google.com" , "Google - Mozilla Firefox"] , _
      ["www.google.com", "Google - Mozilla Firefox"] , _
      ["www.google.com" , "other_title" ] , _
      ["www.google.com" , "other_title" ]]
;~ _ArrayDisplay($A_URL)


For $i = 0 To 1
   ConsoleWrite("running 1 : " & $i & @CRLF)
   Local $ID = ShellExecute("firefox.exe", "-new-window " & $A_URL[$i][0] ,"C:\Program Files\Mozilla Firefox" )
   ConsoleWrite("$ID = " & $ID & @CRLF)
Next

sleep(5000)

$sWinTitle = $A_URL[0][1]
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $sWinTitle = ' & $sWinTitle & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console

$avWinList = WinList("[CLASS:MozillaWindowClass]")
;~ _ArrayDisplay($avWinList)

For $n = 1 to $avWinList[0][0]
    ConsoleWrite("Window " & $n & ":  Title:  " & WinGetTitle($avWinList[$n][1]) & @LF)
    ConsoleWrite("Window " & $n & ":  Text:  " & WinGetText($avWinList[$n][1]) & @LF)
Next

For $i = 1 To $avWinList[0][0]
    WinMove($avWinList[$i][1] , "", $i*50 , $i*50 )
Next

Give this a try...


Rule #1: Always do a backup         Rule #2: Always do a backup (backup of rule #1)

Share this post


Link to post
Share on other sites

@ajag thanks for the reply, I'm a little bit further.
It is somewhat clearer how to deal whit this.

Unfortunaly I'm a little stuck in setting the right window on the right screen.
(This code is meant  to show 4 firefox windows on a computer whit 4 screens)

What I'm trying to do is link 1 on screen 1 and link 2 on screen 2 ......
(resolution is 1920*1080)

When I was trying things out it seems WinList give a random handle back and not in the order it was created (link 1 , link 2 ... ) .
Is there a way around this?

 

#include <Array.au3>
Global $A_URL[4][2] =  _
      [["www.google.com" , "Google - Mozilla Firefox"] , _
      ["www.google.com", "Google - Mozilla Firefox"] , _
      ["www.google.com" , "other_title" ] , _
      ["www.google.com" , "other_title" ]]
      
Global $resolution = 1920
Global $screen_count = 4

If kill_firefox() Then start_firefox()
If win_move() Then login_rotator()

Func kill_firefox()
;~    Run("taskkill /IM firefox.exe /F", "", @SW_HIDE)
;~    Sleep(5000)
   Return True
EndFunc

Func start_firefox()
   For $i = 0 To 3
      Local $ID = ShellExecute("firefox.exe", "-new-window " & $A_URL[$i][0] ,"C:\Program Files\Mozilla Firefox" )
      Sleep(500)
   Next
EndFunc

Func win_move()
   $avWinList = WinList("[CLASS:MozillaWindowClass]")
;~    _ArrayDisplay($avWinList)
   For $i = 1 To $screen_count
      WinMove($avWinList[$i][1] , "", (($i * $resolution) - $resolution) , 0 )
      Sleep(100)
      MouseClick("left", (($i * $resolution) - $resolution) + 10 , 80 )
      Send("{F11}")
      Sleep(1000)
   Next

   Return True

EndFunc

Func login_rotator()
   ;----- login rotator
   Sleep(1000)
   MouseClick("left", 4783 , 362)
   Sleep(2000)
   MouseClick("left", 3935, 552)

   ;----- remove mouse from screen
   MouseMove( 1301, 1078)
EndFunc

 


as finishing touch god created the dutch

Share this post


Link to post
Share on other sites

Okay, then to be a bit more specific, could you please show real links?

I cannot believe that with different links all windows have the same title...


Rule #1: Always do a backup         Rule #2: Always do a backup (backup of rule #1)

Share this post


Link to post
Share on other sites

unfortunaly this isn't posible because the links are inside a coorperate network and not accesible outside.
But I've tried to find something different in a lot of way's , even "Autoit v3 Window Information"-tool doesn't give me something to work whit :(

 


as finishing touch god created the dutch

Share this post


Link to post
Share on other sites

But do all 4 browser windows show the same link (and the same content?)

> if yes, it does not matter witch window is shown on witch monitor, just position them randomly
> if no, then the windows shold have different titles...

I could not understand your problem


Rule #1: Always do a backup         Rule #2: Always do a backup (backup of rule #1)

Share this post


Link to post
Share on other sites

No and yes :) , the first 2 URL's are diffrent but whit the same Title.
The other 2 are diffrent URL and diffrent Title.
It's build something like this, maybe it helps a little?

 

Global $A_URL[5][2] =  _
      [["URL" , "Window title"] , _
      ["http://url1/location1/#/" , "title"] , _
      ["http://url1/location2/#/" , "title"], _
      ["http://url1/location3/#/" , "title_unique1"] , _
      ["http://url1/location4/#/" , "title_unique2"]]

 


as finishing touch god created the dutch

Share this post


Link to post
Share on other sites

You can try to identify the windows based on something different that the title or the text which are the same. I see that those are open in FireFox. You can use the FF udf to identify the windows. You can also use winlist  which will return title+handle so you can move the first window on one place and the second window on the other using the handle.

Share this post


Link to post
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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By MightyWeird
      Hello,
       
      I am trying to learn how this works. I want to be able to interrupt a running  function with winwait.. In this example I want to start notepad and than the script needs to  winwait for a specific window. 
      But if that window does not appear then I want the user to be able to interrupt the function and start the next function (run nextprogram.exe")
      I found some examples and mentioned winwait, but I still could not make it work.
      I tried to adjust the tutorial https://www.autoitscript.com/wiki/Interrupting_a_running_function , but could not get this working either with a winwait 
      I hope someone can put me in the right direction.
      Code below is just one of my many attempts...
      #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> AutoItSetOption("TrayIconDebug", 1) ;0-off ;AutoIt3Wrapper_Run_Debug_Mode=Y ; Set a HotKey HotKeySet("x", "_Interrupt") ; Declare a flag $fInterrupt = 0 $hGUI = GUICreate("Test", 500, 500) $hButton_1 = GUICtrlCreateButton("Func One", 10, 10, 80, 30) $hButton_2 = GUICtrlCreateButton("Func Two", 10, 50, 80, 30) ; Create a dummy control for the Accelerator to action when pressed $hAccelInterupt = GUICtrlCreateDummy() ; Set an Accelerator key to action the dummy control Dim $AccelKeys[1][2]=[ ["z", $hAccelInterupt] ] GUISetAccelerators($AccelKeys) GUISetState() ; Intercept Windows command messages with out own handler GUIRegisterMsg($WM_COMMAND, "_WM_COMMAND") While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $hButton_1 _Func_1() _Func_3() Case $hButton_2 _Func_2() EndSwitch WEnd ; Use a wrapper function in place of the blocking function Func _Func_1() ; Make sure the flag is cleared $fInterrupt = 0 ;For $i = 1 To 20 run ("notepad") ConsoleWrite("-Func 1 Running" & @CRLF) ; Run a modified Sleep function which checks for the interrupt ;if _Interrupt_Sleep(1000) Then ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< if _Interrupt_Sleep(999999999999999999999999999999999) Then ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ; The flag was set Switch $fInterrupt Case 1 ConsoleWrite("!Func 1 interrrupted by Func 2" & @CRLF) Case 2 ConsoleWrite("!Func 1 interrrupted by HotKey" & @CRLF) Case 3 ConsoleWrite("!Func 1 interrrupted by Accelerator" & @CRLF) EndSwitch Return EndIf Sleep(100) ; Next ConsoleWrite(">Func 1 Ended" & @CRLF) EndFunc ;==>_Func_1 ; And here is the wrapper function itself Func _Interrupt_Sleep($iDelay) ; Get a timestamp Local $iBegin = TimerInit() ; And run a tight loop Do ; Use a minimum Sleep (could also be a WinWaitActive with a short timeout) ;Sleep(10) winwait("sdfdf","sdfsdf") ;<<<<<<----- the winwait for a window I want to skip ; Look for the interrrupt If $fInterrupt Then ; And return True immediately if set Return True EndIf Until TimerDiff($iBegin) > $iDelay ; Return False if timed out and no interrupt was set Return False EndFunc ;==>_Interrupt_Sleep Func _Func_2() ;For $i = 1 To 3 processclose("notepad.exe") ConsoleWrite("+Func 2 Running" & @CRLF) Sleep(100) ;Next ConsoleWrite(">Notepad killed!" & @CRLF) EndFunc Func _Func_3() run("nextprogam.exe") Endfunc Func _Interrupt() ; The HotKey was pressed so set the flag $fInterrupt = 2 EndFunc Func _WM_COMMAND($hWnd, $Msg, $wParam, $lParam) ; The Func 2 button was pressed so set the flag If BitAND($wParam, 0x0000FFFF) = $hButton_2 Then $fInterrupt = 1 ; The dummy control was actioned by the Accelerator key so set the flag If BitAND($wParam, 0x0000FFFF) = $hAccelInterupt Then $fInterrupt = 3 Return $GUI_RUNDEFMSG EndFunc ;==>_WM_COMMAND  
    • By nacerbaaziz
      Hello my friends
      Can we create a single context menu on more than one item?
      For example, a context menu includes standardized options on more than one control, such as buttons or check boxes
      to Create a context menu on one item am using this function
      GUICtrlCreateContextMenu ($ HWND)
      How to link it with more than one element please?
      or if we can't do that, please give me a solution
      so i tried to add an context menus to all the controls but the script will be long, for that if their are any solutions i hope to give it to me
      thanks in advanced
    • By MFrancisca
      OK, after days looking at my code, the help file and forums I come (again) for help on message windows.
      I'm having trouble trying to close window messages that appear. This is the code I'm using
      #include <MsgBoxConstants.au3> Local $obs_handler = 0 Opt("WinTitleMatchMode",2) While 1 $obs_handler = WinWait("C:\Users\", "", 1) If IsHWnd($obs_handler) then MsgBox($MB_OK, "Message", "handler: "&$obs_handler, 1) ;Sleep(100) $obs_handler = HWND($obs_handler) WinKill($obs_handler, "") ;<<<<< PROBLEM!!!!! Else MsgBox($MB_OK, "Message", "No handler", 1) EndIf Send("{ESC}") Sleep(2000) $obs_handler = 0 WEnd The problem is on the Winkill command, it won't just close the window! 
      Winwait is capturing the handler, it checks as handler. Ii'm using the HWND() command just to be sure it is the correct variable type.  I've also checked the message box info with the autoit window info tool and the handle value matches the one captured by the code. 
      I've tried winkill, winclose, using wingethandle, moving the winkill command to Before the message box so it is not converted to a string, and now using the hwnd function to force the variable type of the handler. The use of the sleep command does not make any diference.
      As a side quest, I'd like to use classes to capture the windows instead of titles, just to keep things cleaner, but using the [CLASS:...] value for winwait is not working. I have the class name and number, am I missing something? 
       
      Thanks! 
    • By TheAutomator
      Is this better to check a variable before you assign it to a value that could be the same?
      for example:
      local $EmptyLog = false func WriteLog($text) _guictrledit_appendtext($log, ($EmptyLog ? @CRLF : $empty) & $text) If $EmptyLog Then $EmptyLog = False endfunc or does AutoIt behind the scenes already check this?
      i guess overwriting memory with the same value over and over again is not good if you can prevent this with a check?
    • By ur
      if ControlClick("[CLASS:MsiDialogCloseClass]"," ","[CLASS:SysTreeView32; INSTANCE:1]") Then $htreeview=ControlGetHandle($hwnd,"","[CLASS:SysTreeView32; INSTANCE:1]") ControlTreeView($hwnd," ",$htreeview,"Select","#4") The above code worked well to enable the martupgrade feature on windows 7.
      As part of our Installation Testing Automation before delivering the installer to end user.To confirm whether all the screens are working good.

      But it is not working on windows 10.
       
      $h= ControlTreeView($hwnd," ",$htreeview,"Select","#4") The $h is getting value 1,which means error.
×
×
  • Create New...