AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Question of the hour: % Detecting Closure of GUI to App %

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
FireGirl



Joined: 04 May 2007
Posts: 88

PostPosted: Mon Jan 21, 2008 3:06 am    Post subject: Question of the hour: % Detecting Closure of GUI to App % Reply with quote

Hi! Long time no see to everyone on this group Smile

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. Smile

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 Smile

Can someone pelase help me solve this? Smile

Best wishes, %FireGirl%
Back to top
View user's profile Send private message
Mustang



Joined: 17 May 2007
Posts: 375
Location: England

PostPosted: Mon Jan 21, 2008 3:46 am    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group