 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
FireGirl
Joined: 04 May 2007 Posts: 88
|
Posted: Mon Jan 21, 2008 3:06 am Post subject: Question of the hour: % Detecting Closure of GUI to App % |
|
|
Hi! Long time no see to everyone on this group
I've been bugged out trying to solve this minor issue to reconcile a GUI detection scenario. What it is, is this:
I need to detect the closure of a application. I am running this third-party app, and need AHK to do something when the user closes the app, like GOSUB, SOMEWHERE. So, well, I can get the name of the App Window using the handy AHK Active Window Info utility.
Basically, I need some active-persistent running AHK routine which can be alerted when XYZ is closed, ... and then be ready to do something, like go to some GOSUB routine on the mark when it is closed
Can someone pelase help me solve this?
Best wishes, %FireGirl% |
|
| Back to top |
|
 |
Mustang
Joined: 17 May 2007 Posts: 375 Location: England
|
Posted: Mon Jan 21, 2008 3:46 am Post subject: |
|
|
Change the red text to the process name of the 3rd party application
Make sure you start the AHK script before launching the 3rd party application (reason: on closure there isn't enough time to get a window's title or process name, so instead this is done when the window is created)
Make sure you only run the 3rd party application once as only the last instance is remembered (this can probably be fixed but it in most cases isn't needed so I didn't bother implementing it - more code, more time)
| Code: | #NoEnv
#NoTrayIcon
#Persistent
#SingleInstance, Force
Process, Priority,, High
SetBatchLines, -1
SetWorkingDir, %A_ScriptDir%
RegisterShellHook()
Return
RegisterShellHook()
{
Gui, +LastFound
ScriptHandle := WinExist()
DllCall( "RegisterShellHookWindow", "UInt", ScriptHandle )
ShellHookMessageIdentifier := DllCall( "RegisterWindowMessage", "Str", "SHELLHOOK" )
OnMessage( ShellHookMessageIdentifier, "ShellMessage" )
Return
}
ShellMessage( wParam, lParam )
{
Static WindowHandle
If ( wParam = (HSHELL_WINDOWCREATED:=1) )
{
WinGet, WindowProcessName, ProcessName, ahk_id %lParam%
If ( WindowProcessName = "notepad.exe" )
{
WindowHandle := lParam
}
}
Else If ( wParam = (HSHELL_WINDOWDESTROYED:=2) )
{
If ( lParam = WindowHandle )
{
GoSub, WindowDestroyed
}
}
Return
}
WindowDestroyed:
{
MsgBox, Application Has Been Closed
Return
} |
|
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|