AutoHotkey Community

It is currently May 25th, 2012, 5:54 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: [tutorial] WinEvent Hook
PostPosted: August 27th, 2007, 9:48 am 
Offline

Joined: May 24th, 2006, 2:49 pm
Posts: 4511
Location: Belgrade
Recent callback addition to AHK language makes us able to create so called "out of context" hooks. This eliminites need for separate hook dll that is for instance used in Dock module.

This is the sample how to monitor when system menu is open/closed.

Code:
CoordMode, tooltip, screen
#SingleInstance, force
#Persistent
   HookProcAdr := RegisterCallback("HookProc", "F" )
   API_SetWinEventHook(4,5,0,HookProcAdr,0,0,0)
   API_SetWinEventHook(0xA,0xB,0,HookProcAdr,0,0,0)
return

HookProc(hWinEventHook, event, hwnd, idObject, idChild, dwEventThread, dwmsEventTime ){
   if event = 4
       s := "Menu start"
   else if event = 5
       s := "Menu close"
   else if event = 10
       s := "Moving started"
   else s := "Moving stoped"
      
   ToolTip, %s%, 0, 0
}

API_SetWinEventHook(eventMin, eventMax, hmodWinEventProc, lpfnWinEventProc, idProcess, idThread, dwFlags) {
   DllCall("CoInitialize", "uint", 0)
   return DllCall("SetWinEventHook", "uint", eventMin, "uint", eventMax, "uint", hmodWinEventProc, "uint", lpfnWinEventProc, "uint", idProcess, "uint", idThread, "uint", dwFlags)
}

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 31st, 2008, 10:14 am 
hi majkinetor
thanks for kindly tutorial (i just wonder that why no replies here?)
i've tried to make a replacement of sysmenu. but there were few problems

1) can i hook sysmenu only? rather than all popup menus by right mouse click

2) is there more elegant way rather than closing sysmenu by sending {ALT} key?
Thanks !!!
Code:
#SingleInstance, force
#Persistent
SetKeyDelay, -1 ;close sysmenu real fast!!!
SetBatchLines, -1

   HookProcAdr := RegisterCallback("HookProc", "F" )
   API_SetWinEventHook(4,5,0,HookProcAdr,0,0,0)
   API_SetWinEventHook(0xA,0xB,0,HookProcAdr,0,0,0)
Menu, Replacement, Add, SysMenu Hook Testing!!!, Test
Test:
return

HookProc(hWinEventHook, event, hwnd, idObject, idChild, dwEventThread, dwmsEventTime ) {
   if event = 4
   {
       Send, {Alt} ;close sysmenu!!!
       Menu, Replacement, Show

   }
}

API_SetWinEventHook(eventMin, eventMax, hmodWinEventProc, lpfnWinEventProc, idProcess, idThread, dwFlags) {
   DllCall("CoInitialize", "uint", 0)
   return DllCall("SetWinEventHook", "uint", eventMin, "uint", eventMax, "uint", hmodWinEventProc, "uint", lpfnWinEventProc, "uint", idProcess, "uint", idThread, "uint", dwFlags)
}


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: May 31st, 2008, 10:19 am 
the "Sysmenu" i mentioned was meant for System Menu that pops up from caption bar or when pressing Alt+Space
Thanks!!!


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: May 31st, 2008, 2:07 pm 
Offline

Joined: May 24th, 2006, 2:49 pm
Posts: 4511
Location: Belgrade
I don't know at the moment but I also had need for that so I will check out. If I find out anything useful, I will let you know.

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 14th, 2010, 1:26 pm 
does this allow to mimic the functionality of the Detours library?
http://www.codeproject.com/KB/DLL/funapihook.aspx


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: April 14th, 2010, 7:35 pm 
Offline

Joined: May 24th, 2006, 2:49 pm
Posts: 4511
Location: Belgrade
Not even close. The Detours can attach to functions or replace them. The hook is simply function that is called by the system on specific events.

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 14th, 2010, 11:14 pm 
majkinetor wrote:
Not even close. The Detours can attach to functions or replace them. The hook is simply function that is called by the system on specific events.


i see. is there any AHK equivalent of hooking into functions of other apps?


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: April 15th, 2010, 7:24 am 
No. You should look into that from C++ perspective.


Report this post
Top
  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: nothing and 15 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group