ATTENTION: You are viewing a page formatted for mobile devices; to view the full web page, click HERE.

Other Software > Developer's Corner

Crazy Autohotkey issue

<< < (2/2)

jpprater:
thanks for the explanation, could help others  :up:
-mouser (December 14, 2009, 03:43 PM)
--- End quote ---
kudos for sticking at it AND advising the fix :Thmbsup:
-Target (December 14, 2009, 04:01 PM)
--- End quote ---
Thank you, mouser and Target. :) The DllCall relied on having a valid hWnd for the script's window, but it was written based on the script running in the AutoHotkey interpreter, not compiled independently.  The class was still the same, but the window title wouldn't match anymore because the title of a compiled Autohotkey script's window becomes the path to the executable (unless otherwise set).

tatysek:
Finally figured it out.  The FindWindowEx call in LockDetect.ahk wasn't finding a valid hWnd for the script after compilation.  Changing the values in that call fixed it.
-jpprater (December 14, 2009, 02:28 PM)
--- End quote ---
@jpprater
What was the change you applied? Can you please post new code? Thanks

jpprater:
This code right here in LockDetect.ahk:

--- Code: Autohotkey ---hw_ahk := FindWindowEx( 0, 0, "AutoHotkey", a_ScriptFullPath " - AutoHotkey v" a_AhkVersion )This had to be changed to accurately reflect the title of the compiled script's window.
I don't have the code available to me just now, but I'll post it tomorrow.  If you compile the script yourself and try to run it, and then open the script's window, you'll see what the proper title to match is.

jpprater:
This is the updated LockDetect.ahk.  Changes between this version and the original are on line 46 and the additional constants on lines 29-39.

--- Code: Autohotkey ---;--------------------------------------------------------------- ;Notify Lock\Unlock;   This script monitors LockWorkstation calls;;   If a change is detected it 'notifies' the calling script;      On Lock;         This script will call function "on_lock()";      On Unlock;         This script will call fucntion "on_unlock()";IMPORTANT: The functions "on_lock()" and "on_unlock()" DO NOT;exist in this script, they are to be created in the script that;calls notify_lock_unlock() (presumably your main script);---------------------------------------------------------------;Re-purposed by WTO605;Last edited 2009-08-18 16:34 UTC;---------------------------------------------------------------;Based on Winamp_Lock_Pause by MrInferno;Posted: Fri Apr 21, 2006 4:49 am;Source: http://www.autohotkey.com/forum/topic9384.html;---------------------------------------------------------------;Winamp_Lock_Pause was/is based on script codes from "shimanov";Posted: Thu Sep 15, 2005 12:26 am   ;Source: http://www.autohotkey.com/forum/viewtopic.php?t=5359;Posted: Tue Dec 06, 2005 9:14 pm;Source: http://www.autohotkey.com/forum/viewtopic.php?t=6755;--------------------------------------------------------------- ;Initialize global constantsWTS_CONSOLE_CONNECT := 0x1WTS_CONSOLE_DISCONNECT := 0x2WTS_REMOTE_CONNECT := 0x3WTS_REMOTE_DISCONNECT := 0x4WTS_SESSION_LOGON := 0x5WTS_SESSION_LOGOFF := 0x6WTS_SESSION_LOCK      :=   0x7WTS_SESSION_UNLOCK      :=   0x8NOTIFY_FOR_ALL_SESSIONS   :=   1NOTIFY_FOR_THIS_SESSION   :=   0WM_WTSSESSION_CHANGE   :=   0x02B1 notify_lock_unlock(){   Global WM_WTSSESSION_CHANGE   Global NOTIFY_FOR_ALL_SESSION    hw_ahk := FindWindowEx( 0, 0, "AutoHotkey", A_ScriptFullPath )    OnMessage( WM_WTSSESSION_CHANGE, "Handle_WTSSESSION_CHANGE" )     success := DllCall( "wtsapi32.dll\WTSRegisterSessionNotification", "uint", hw_ahk, "uint", NOTIFY_FOR_ALL_SESSIONS )    if( ErrorLevel OR ! success )    {      success := DllCall( "wtsapi32.dll\WTSUnRegisterSessionNotification", "uint", hw_ahk )      ;If DLL registration fails, wait 20 seconds and try again      Sleep, 20000      notify_lock_unlock()      ;MsgBox, [WTSRegisterSessionNotification] failed: EL = %ErrorLevel%   }   return} Handle_WTSSESSION_CHANGE( p_w, p_l, p_m, p_hw ); p_w  = wParam   ;Session state change event; p_l  = lParam   ;Session ID; p_m  = Msg   ;WM_WTSSESSION_CHANGE; p_hw = hWnd   ;Handle to Window{   Global WTS_SESSION_LOCK   Global WTS_SESSION_UNLOCK   Global WTS_SESSION_LOGON   Global WTS_SESSION_LOGOFF    If ( p_w = WTS_SESSION_LOCK )    {      on_lock()   }   Else If ( p_w = WTS_SESSION_UNLOCK )    {      on_unlock()   }   Else If (p_w = WTS_SESSION_LOGON)   {      on_logon()   }   Else If (p_w = WTS_SESSION_LOGOFF)   {      on_logoff()   }} FindWindowEx( p_hw_parent, p_hw_child, p_class, p_title ) {   return, DllCall( "FindWindowEx", "uint", p_hw_parent, "uint", p_hw_child, "str", p_class, "str", p_title ) }

tatysek:
That was exactly what I was looking for, big thank you!

Navigation

[0] Message Index

[*] Previous page

Go to full version