Give this a shot & see what it does for you.
;http://www.autohotkey.com/board/topic/19672-detect-when-a-new-window-is-opened/
;DLLCall / Shell / MsgBox = SKAN
;-------------------------------------------------------------------
;--Program monitors newly opened windows & maximizes accordingly--
;-------------------------------------------------------------------
#SingleInstance, force
#Persistent
#NoEnv
SetTitleMatchMode, 2
SetWorkingDir %A_ScriptDir%
DetectHiddenWindows, on
onexit, exitsub
Gui +LastFound
hWnd := WinExist()
DllCall( "RegisterShellHookWindow", UInt,hWnd )
MsgNum := DllCall( "RegisterWindowMessage", Str,"SHELLHOOK" )
OnMessage( MsgNum, "ShellMessage" )
Return
ShellMessage( wParam,lParam )
{
Local k
If ( wParam = 1 ) ; HSHELL_WINDOWCREATED := 1
{
NewID := lParam
SetTimer, MsgBox, -1
}
}
MsgBox:
WinGetTitle, Title, ahk_id %NewID%
WinGetClass, Class, ahk_id %NewID%
WinWait, ahk_id %NewID%
;add items you do NOT want maximized here... e.g. Properties Window (Alt+Enter), WinRar, etc.
;*Note: WinTitles need to be case sensitive
if InStr(Title, "Properties") || InStr(Title, "WinRar")
return
else
minmax_func()
Return
ralt & Esc:: ;right Alt key & Esc
exitsub:
{
critical
Exitapp
}
;=================
;==Function(s)====
;=================
minmax_func()
{
global NewID, minmax
WinGet, minmax, minmax, ahk_id %NewID%
if (minmax=0)
{
WinMaximize, ahk_id %NewID%
;use PostMessage for stubborn windows
;PostMessage, 0x112, 0xF030,,, NewID ; 0x112 = WM_SYSCOMMAND, 0xF030 = SC_MAXIMIZE
}
else
if (minmax=-1)
{
WinRestore, ahk_id %NewID%
}
}