1

I'm attempting to open up a Chrome instance with the -app flag, then move that window around and generally do stuff with it. Here's my code:

#!NumpadMult::
{
    Gui, Show , w260 h150, Window title
    Gui, Add, Edit, w100 vCustomUrl, http://
    Gui, Add, Button, default, OK  ; The label ButtonOK (if it exists) will be run when the button is pressed.

    ButtonOk:
    Gui, Submit
    Gui, Destroy
    URL = %customUrl%

    MyWidth = 639
    MyHeight = 389
    Run C:\Program Files (x86)\Google\Chrome\Application\chrome.exe --app=data:text/html`,<html><body><script>window.resizeTo(%MyWidth%`,%MyHeight%)`;window.location='%URL%'`;</script></body></html>

    return
}

This is the best way I've found so far to open a Chrome window and move it around, because I can't figure out how to actually do a WinWait on a specific Chrome window for which I don't know the title. If I try to have Run spit out a pid, the pid is the same as any existing Chrome processes, so the window I get isn't necessarily the one I created.

Any ideas? I am happy to provide more information if needed.

1

1 Answer 1

0
MyWidth = 639
MyHeight = 389

InputBox, customUrl, Custom Url, Enter an URL., , 1000, 120
if ErrorLevel
    return
run % "chrome.exe" ( winExist("ahk_class Chrome_WidgetWin_1") ? " --new-window " : " " ) customUrl      ; https://autohotkey.com/board/topic/82062-open-google-chrome-in-new-instance/
ID := WinWaitCreated("ahk_class Chrome_WidgetWin_1")
WinWait, ahk_id %ID%
WinMove, ahk_id %ID%,,,,%MyWidth%,%MyHeight%
IfWinNotActive, ahk_id %ID%, ,WinActivate,ahk_id %ID%
return


WinWaitCreated( WinTitle:="", WinText:="", Seconds:=0, ExcludeTitle:="", ExcludeText:="" ) {
    ; HotKeyIt - http://ahkscript.org/boards/viewtopic.php?t=1274
    static Found := 0, _WinTitle, _WinText, _ExcludeTitle, _ExcludeText 
         , init := DllCall( "RegisterShellHookWindow", "UInt",A_ScriptHwnd )
         , MsgNum := DllCall( "RegisterWindowMessage", "Str","SHELLHOOK" )
         , cleanup:={base:{__Delete:"WinWaitCreated"}}
  If IsObject(WinTitle)   ; cleanup
    return DllCall("DeregisterShellHookWindow","PTR",A_ScriptHwnd)
  else if (Seconds <> MsgNum){ ; User called the function
    Start := A_TickCount, _WinTitle := WinTitle, _WinText := WinText
    ,_ExcludeTitle := ExcludeTitle, _ExcludeText := ExcludeText
    ,OnMessage( MsgNum, A_ThisFunc ),  Found := 0
    While ( !Found && ( !Seconds || Seconds * 1000 < A_TickCount - Start ) ) 
      Sleep 16                                                         
    Return Found,OnMessage( MsgNum, "" )
  }
  If ( WinTitle = 1   ; window created, check if it is our window
    && ExcludeTitle = A_ScriptHwnd
    && WinExist( _WinTitle " ahk_id " WinText,_WinText,_ExcludeTitle,_ExcludeText))
    WinWait % "ahk_id " Found := WinText ; wait for window to be shown
}
1

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .