) a little bit to include the size of the window instead of the position only.
Code: Select all
rel_X:=160, relY:=100
if !WinExist("ahk_class Notepad"){
run notepad.exe
WinWaitActive, ahk_class Notepad
}
WinActivate, ahk_class Notepad
WinGet, PID, PID, % "ahk_id " . owner:=WinExist()
GUI, +ToolWindow +Owner%owner% +Hwndowned
GUI, Show, w100 h300
OnLocationChangeMonitor(owner, owned, PID) ; INIT
WinWaitClose % "ahk_id " . owner
ExitApp
OnLocationChangeMonitor(_hWinEventHook, _event, _hwnd) { ; https://msdn.microsoft.com/en-us/library/windows/desktop/dd373885(v=vs.85).aspx
STATIC ox, oy, ow, ownerAhkId, ownedAhkId, hWinEventHook
global rel_X,relY
IF !_hwnd ; if the system sent the EVENT_OBJECT_LOCATIONCHANGE event for the caret:
Return ; https://msdn.microsoft.com/en-us/library/windows/desktop/dd318066(v=vs.85).aspx
IF !hWinEventHook ; register a event hook function for EVENT_OBJECT_LOCATIONCHANGE := "0x800B"
hWinEventHook := SetWinEventHook("0x800B", "0x800B",0, RegisterCallback("OnLocationChangeMonitor"),_hwnd,0,0)
, ownerAhkId := _hWinEventHook, ownedAhkId := _event, OnExit(Func("UnhookWinEvent").Bind(hWinEventHook))
WinGetPos, _x, _y,_w,_h, ahk_id %ownerAhkId%
WinGetPos, _x1, _y1,,, ahk_id %ownedAhkId%
iF (_!=ox || _y1!=oy || _w!=ow){
ow:=_w,ox:=_x,oy:=_y
WinMove, ahk_id %ownedAhkId%,, % ox:=_x+_w-rel_X, % oy:=_y+relY
}
}
SetWinEventHook(_eventMin, _eventMax, _hmodWinEventProc, _lpfnWinEventProc, _idProcess, _idThread, _dwFlags) {
DllCall("CoInitialize", "Uint", 0)
return DllCall("SetWinEventHook","Uint",_eventMin,"Uint",_eventMax,"Ptr",_hmodWinEventProc,"Ptr",_lpfnWinEventProc,"Uint",_idProcess,"Uint",_idThread,"Uint",_dwFlags)
} ; cf. https://autohotkey.com/boards/viewtopic.php?t=830
UnhookWinEvent(_hWinEventHook) {
DllCall("UnhookWinEvent", "Ptr", _hWinEventHook)
DllCall("CoUninitialize")
} ; cf. https://autohotkey.com/boards/viewtopic.php?t=830