Jump to content

Script to Create New Instance of Program and Restore that Instance


Recommended Posts

Hey, so as the title implies, I'm trying to create a basic script to open a new Firefox window, and restore that window if minimized or in background. I'm a newbie at this, so I'm not sure how I can return the class name of that new window to a variable and have AutoIt use that variable in the title of WinSetState. Can you guys help me out with this? There's gotta be some way to do it, I'm just short on knowledge. :P Thanks!

Link to comment
Share on other sites

Please before you get in massive trouble. READ THE STUPID FORUM RULES!

AND the Help files.. 

Start with this and never post again without SHOWING your code you have made,,

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Opt("GUIOnEventMode", 1)
#Region ### START Koda GUI section ### Form=C:\AutoIt3\KODA\openHtml.kxf
$Form1 = GUICreate("open Html", 623, 443, 192, 122)
GUISetOnEvent($GUI_EVENT_CLOSE, "Form1Close")
GUISetOnEvent($GUI_EVENT_MINIMIZE, "Form1Minimize")
GUISetOnEvent($GUI_EVENT_MAXIMIZE, "Form1Maximize")
GUISetOnEvent($GUI_EVENT_RESTORE, "Form1Restore")
$openxxxx = GUICtrlCreateButton("open Min", 48, 224, 75, 25)
GUICtrlSetOnEvent($openxxxx, "openxxxxClick")
$openxx = GUICtrlCreateButton("open Max", 168, 224, 75, 25)
GUICtrlSetOnEvent($openxx, "openxxClick")
$openx = GUICtrlCreateButton("open html", 288, 224, 75, 25)
GUICtrlSetOnEvent($openx, "openxClick")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    Sleep(100)
WEnd

Func Form1Close()
Exit
EndFunc
Func Form1Maximize()
ShellExecute(@ScriptDir & "\page.html","" ,@SW_MAXIMIZE ) ; Your page
;ShellExecute(@ScriptDir & "\page.html") ; Your page
EndFunc
Func Form1Minimize()
ShellExecute(@ScriptDir & "\page.html","",@SW_MINIMIZE ) ; Your page
EndFunc
Func Form1Restore()
ShellExecute(@ScriptDir & "\page.html","",@SW_RESTORE) ; Your page
EndFunc
Func openxClick()
ShellExecute(@ScriptDir & "\page.html","" ,@SW_MAXIMIZE ) ; Your page
EndFunc
Func openxxClick()
ShellExecute(@ScriptDir & "\page.html") ; Your page
EndFunc
Func openxxxxClick()
ShellExecute(@ScriptDir & "\page.html") ; Your page
EndFunc



ShellExecute(@ScriptDir & "\page.html",WinSetState("[ACTIVE]", "", @SW_MAXIMIZE)) ; Your page

;WinSetState("[ACTIVE]", "", @SW_RESTORE) will @SW_RESTORE the currently active window.
;WinSetState("[ACTIVE]", "", @SW_MINIMIZE) will @SW_MINIMIZE the currently active window.

 

Link to comment
Share on other sites

Wow Meows... Mind your blood pressure will you? :) Of course, posting code you have already tried goes a long way to get effort from others, you're right, giving fish vs. teaching to fish and all, but for someone with 63 posts to talk to someone with 3 posts like that? Wow.

Anyway, in my opinion the question is specific enough to get a specific answer. He's not asking anyone to write an entire script from scratch, he's asking how to work with a class name when he only knows the PID. The problem here of course is that all FF windows have the same class name, so how to tell the FF window you spawned from within the script from any other possible FF windows?

I wrote an example that's a lot more to the point, I think. hope it helps:
 

$ffpid = Run("c:\program files (x86)\Mozilla Firefox\firefox.exe -new-window www.google.com")

While True
    $ar = WinList("[CLASS:MozillaWindowClass]")

    For $i = 1 To $ar[0][0]
        $handle = $ar[$i][1]
        If WinGetProcess($handle) == $ffpid Then
            ;WinSetState($handle, @SW_<whatever>
            ;WinActivate($handle)
            ; ... etc...
        EndIf
    Next

    sleep(1000)
WEnd
Edited by SadBunny

Roses are FF0000, violets are 0000FF... All my base are belong to you.

Link to comment
Share on other sites

Hey, thanks for the quick response. I think I can figure out how to get a new window to open, remember its handle, and open that specific window on-command now, but I need to figure something out that seems somewhat more complex...

I currently have Firefox setup so that it remembers what windows and tabs I have open, so that when I restart my PC, opening Firefox re-opens all of those windows that I had open before. The window order gets rearranged every restart, which is odd. Anyway, how can I create a script that opens/maximizes a specific window after Firefox is opened? This is difficult because the window title changes whenever I change tabs, and the handles reset every startup. Any ideas?

I'm still not very good at this, so bear with me here :)

Edited by sonicriders
clarification
Link to comment
Share on other sites

  • Moderators

meows,

READ THE STUPID FORUM RULES!

While we are grateful that you all try to keep this forum the kind of place we want it to be, please do not be too aggressive, particularly to new members. If there is some doubt as to the legality of the subject (which from what I can see does not apply in this case) report the thread so that a Mod can take a look - that is why we are here. And I do hope that that your choice of the adjective "stupid" merely replaced something rather more explicit rather than expressing your thoughts about the rules themselves.

sonicriders,

Welcome to the AutoIt forums.

M23

Edit:

And meows, can you please set up your email to stop sending auto-replies whenever you get an email notification from the forum - we get enough crap in that inbox already.  Yours is the only account which does this and we would be grateful if you could make it stop.  Thanks in advance.

Edited by Melba23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

From the outside I think the best you can do is manipulate Firefox with Send to cycle through the tabs and check the window Title for the one you are looking for.

By default Send("^{Tab}") should move to the next tab in Firefox.  The only way I know to cycle through the tabs is to Send to switch to next tab, compare the title to the starting title to see if you have come full circle.  Of course if you have duplicate tabs this will mess you up.  But assuming you have unique titles in all the tabs the scheme may work.

After cycling through all the tabs move to the next FF window.  Maybe using Group Add would make this easier.

 

Link to comment
Share on other sites

So So sorry all. Indeed it was a very terrible day.

meows,

While we are grateful that you all try to keep this forum the kind of place we want it to be, please do not be too aggressive, particularly to new members. If there is some doubt as to the legality of the subject (which from what I can see does not apply in this case) report the thread so that a Mod can take a look - that is why we are here. And I do hope that that your choice of the adjective "stupid" merely replaced something rather more explicit rather than expressing your thoughts about the rules themselves.

sonicriders,

Welcome to the AutoIt forums.

M23

Edit:

And meows, can you please set up your email to stop sending auto-replies whenever you get an email notification from the forum - we get enough crap in that inbox already.  Yours is the only account which does this and we would be grateful if you could make it stop.  Thanks in advance.

​Yes you are correct. I was the stupid one not the rules. And I shall see if I can find out how to stop Thunderbird to stop sending auto-replys to specific addresses.

Link to comment
Share on other sites

I found this but they did not put their name in the top of the script.. It should do what you want

Play with it a bit and you can call each window as you please.. 

 

#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include <ExtMsgBox.au3>
#include <XSkin.au3>
#include <XSkinShell.au3>
;BED442B1-997B-4f34-BBA2-CBF4B7EE357F
 MsgBox ( 4096 ,  "" ,  "Window 1 enabled" )
_winwaitActivate ( "Window 1" , "" ,  2 )

Switch  WinGetTitle ( "[ACTIVE]" )
   Case  "Window 1"
      MsgBox ( 4096 ,  "" ,  "Window 1 enabled" )
   Case  "Window 2"
      MsgBox ( 4096 ,  "" ,  "Window 2 activated" )
   Case  Else
      MsgBox ( 4096 ,  "" ,  "No activated window" )
Endswitch

Func _WinWaitActivate ( $title , $text , $timeout = 0 )
   WinWait ( $title , $text , $timeout )
   If  Not  WinActive ( $title , $text )  Then  WinActivate ( $title , $text )
   WinWaitActive ( $title , $text , $timeout )
EndFunc

Now what I did to test this is this

#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include <ExtMsgBox.au3>
;; #include <XSkin.au3>
;; #include <XSkinShell.au3>
 MsgBox ( 4096 ,  "" ,  "Window 1 enabled" )
 ;; copied window one to open at start
#cs ;;;; By adding window 1 or window2 at the top you can open it and close it at will. This is edited from what I found in the forums, I added the Xskin to see what could be changed.. if using a GUI remember to  GUIDelete($GUI_NAME) when you change windows. M23 could advise you a lot better,. 
#ce
_winwaitActivate ( "Window 1" , "" ,  2 )
      MsgBox ( 4096 ,  "" ,  "Window 2 activated" )
Switch  WinGetTitle ( "[ACTIVE]" )
   Case  "Window 1"
      MsgBox ( 4096 ,  "" ,  "Window 1 enabled" )
   Case  "Window 2"
      MsgBox ( 4096 ,  "" ,  "Window 2 activated" )
   Case  Else
      MsgBox ( 4096 ,  "" ,  "No activated window" )
Endswitch

Func _WinWaitActivate ( $title , $text , $timeout = 0 )
   WinWait ( $title , $text , $timeout )
   If  Not  WinActive ( $title , $text )  Then  WinActivate ( $title , $text )
   WinWaitActive ( $title , $text , $timeout )
EndFunc

Because i could not get a understanding on how to use tabs I really like this method.

Link to comment
Share on other sites

Hey Meows, thanks for taking the time to do that. I've found a far simpler method for the time being, but that code might come in very handy for other stuff I have yet to do...

I found a Godsend Firefox plugin that let me rename my firefox windows, and even when Firefox is restarted, the titles stay! :) I'm sure you can all see just how handy this truly is. So pleased!

Thanks for all of your help, people!

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...