Created
April 1, 2016 11:18
-
-
Save TLMcode/a42ea458a3ac6fa7f2a9ea0e241dbd53 to your computer and use it in GitHub Desktop.
RunChrome() waits for page to load then moves the chrome window to the coordinate array.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
new RunChrome( "https://autohotkey.com", [ 0, 0, 1000, 500 ] ) | |
return | |
Esc::ExitApp | |
class RunChrome | |
{ | |
__New( url, coords ) | |
{ | |
this.arr := this.EnumWindows(), this.ShellHookWindow( 1 ) | |
this.coords := coords | |
Run % "chrome.exe -new-window " url | |
return this | |
} | |
EnumWindows() | |
{ | |
return ComObjGet("winmgmts:").ExecQuery("Select * from Win32_Process WHERE name = 'chrome.exe'") | |
} | |
ShellHookWindow( typ ) | |
{ | |
static msgNum | |
Gui +LastFound | |
DllCall( ( typ = 0 ? "Der" : "R" ) "egisterShellHookWindow", UInt, WinExist() ) | |
OnMessage( typ != 0 ? (msgNum := DllCall( "RegisterWindowMessage", Str, "SHELLHOOK" ) ) : msgNum, (typ = 1 ) ? this.ShellEventHandler.Bind( this ) : ) | |
} | |
ShellEventHandler( msg, wP ) | |
{ | |
WinGet, wProc, ProcessName, % "ahk_id " wP | |
if ( wProc = "chrome.exe" ) | |
pidArr := this.EnumWindows() | |
WinGetTitle, wTitle, % "ahk_id " wP | |
if ( pidArr.count() > this.arr.count() && !InStr( wTitle, "Legacy" ) ) | |
{ | |
WinMove, % "ahk_id " wP,, % this.coords.1, % this.coords.2, % this.coords.3, % this.coords.4 | |
this.ShellHookWindow( 0 ) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment