Sign in to follow this  
Followers 0
pekster

AutoIt Window Title

6 posts in this topic

I'm trying to get two instances of the same script to talk to each other, but I have encountered a problem. Using the code below, I can click the "GUI 1" button to make that GUI appear by running a 2nd instance of the same script. However, when I quit the main GUI, the 2nd instance does not properly read the change in the hidden AutoIt window title. I am further perplexed by the fact that my debug message in the main GUI upon exit reports the proper window title. Clearly, the 2nd instance is not recieving this properly because the tooltip in the upper left corner doesn't ever change.

Note: For this code to work as-is, you must compile it so that the 2nd instance will start.

My code:

If $CmdLine[0] = 1 AND $CmdLine[1] = "GUI1" Then Gui1()
;If $CmdLine[0] = 1 AND $CmdLine[1] = "GUI2" Then Gui2()

GuiCreate("Main GUI", 200, 50)
  $GUI1 = GuiSetControl("button", "GUI 1", 0, 0, 100, 20)
    GuiSetControlNotify()
;  $GUI2 = GuiSetControl("button", "GUI 2", 100, 0, 100, 20)
;    GuiSetControlNotify()
  $quit = GuiSetControl("button", "Quit Script", 50, 30, 100, 20)
    GuiSetControlNotify()
GuiShow()

While 1
  Sleep(100)
  $msg = GuiMsg(0)
  If $msg = -3 OR $msg = $quit Then
    AutoItWinSetTitle("quit");notify other instances that we're quitting
    Sleep(500);give them extra time to respond
   ;next 2 lines are debugging to show that the title was set properly
    $title = AutoItWinGetTitle()
    MsgBox(0, "Title", "Ending AuotIt window title was: " & $title)
    Exit
  EndIf
  If $msg = $GUI1 Then Run(@ScriptFullPath & " GUI1")
;  If $msg = $GUI2 Then Run(@ScriptFullPath & " GUI2")
WEnd

Func Gui1()
  Opt("TrayIconHide", 1);no need for a 2nd A in the tray
  GuiCreate("GUI 1", 200, 50, 100, 100)
    GuiSetControl("label", "This is an instance of the 1st sub-GUI",_
     0, 0, 200, 20)
    $quit = GuiSetControl("button", "Close Window", 50, 30, 100, 20)
  GuiShow()

  While 1
   ;next 2 lines are debugging to show that the title is not recieved:
    $parent = AutoItWinGetTitle()
    ToolTip($parent, 0, 0)
    Sleep(100)
    $msg = GuiMsg(0)
    If $parent = "quit" OR $msg = -3 OR $msg = $quit Then Exit
  WEnd
EndFunc

[font="Optima"]"Standing in the rain, twisted and insane, we are holding onto nothing.Feeling every breath, holding no regrets, we're still looking out for something."[/font]Note: my projects are off-line until I can spend more time to make them compatable with syntax changes.

Share this post


Link to post
Share on other sites



There is a hidden window with EVERY instance of the script. When you call AutoItWinSetTitle() then immediately call Exit, you destroy the window the other script is supposed to be reading.

Share this post


Link to post
Share on other sites

Don't you have to change the AutoItWindow title to something else?

You will have 2 autoitwindows with the same title so how do you determine which one to check ??


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

There is a hidden window with EVERY instance of the script.  When you call AutoItWinSetTitle() then immediately call Exit, you destroy the window the other script is supposed to be reading.

I'm not just setting it and exiting: I set it, and then wait half a second for all spawned instances to read it. I check every 1/10th of a second for a change, so that should be allright. If every instance has this window, should I just use a WinExist call instead of the AutoItWinGetTitle that I am using?

Edit: This worked. I just need to check for the window to exist, since each script has its own window. Thanks for your help. I just didn't realise that each script had its own hidden window.

Edited by pekster

[font="Optima"]"Standing in the rain, twisted and insane, we are holding onto nothing.Feeling every breath, holding no regrets, we're still looking out for something."[/font]Note: my projects are off-line until I can spend more time to make them compatable with syntax changes.

Share this post


Link to post
Share on other sites

What about doing it this way:

At the start:

If $CmdLine[0] = 1 AND $CmdLine[1] = "GUI1" Then
   AutoItWinSetTitle("GUI1:Run")
   Gui1()
Else
   AutoItWinSetTitle("MainScript:Run")
EndIf

To signal the quit:

AutoItWinSetTitle("MainScript:quit");notify other instances that we're quitting

Last portion of your script:

While 1
 ;next 2 lines are debugging to show that the title is not recieved:
   $parent = WinGetTitle("MainScript:")
   ToolTip($parent, 0, 0)
   Sleep(100)
   $msg = GuiMsg(0)
   If $parent = "MainScript:quit" OR $msg = -3 OR $msg = $quit Then Exit
 WEnd

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

Yea, thanks JdeB :D. I had a slightly more crude version of a similar approach, but yours seems much better.


[font="Optima"]"Standing in the rain, twisted and insane, we are holding onto nothing.Feeling every breath, holding no regrets, we're still looking out for something."[/font]Note: my projects are off-line until I can spend more time to make them compatable with syntax changes.

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  
Followers 0