WH_SHELL-Hook
Posted: Thu Oct 21, 2004 6:44 am
Hello @all,
i try to hook the SH_SHELL-Events to determine that a window will be
opened (created) and closed (destroyed). But with this code i get the
messages at the wrong time.
For example: I open a window (in my code nothing happens) and close it
(i get 3(!) Create-Messages). When i move my mouepointer over the
captionbar of my window, i get Destroy-Messages.
Who can help?
Thanks in advance ... Kiffi
and here is my Hook-DLL:
i try to hook the SH_SHELL-Events to determine that a window will be
opened (created) and closed (destroyed). But with this code i get the
messages at the wrong time.
For example: I open a window (in my code nothing happens) and close it
(i get 3(!) Create-Messages). When i move my mouepointer over the
captionbar of my window, i get Destroy-Messages.
Who can help?
Thanks in advance ... Kiffi
Code: Select all
#HookDll = 1
myHook.l
Procedure HookProc(Hooked)
Shared myHook
If Hooked = 1
myDLL.l = OpenLibrary(#HookDll,"hook.dll")
myDLLFunction.l = IsFunction(#HookDll,"ShellHook")
myHook = SetWindowsHookEx_(#WH_SHELL, myDLLFunction, myDLL, 0)
Else
UnhookWindowsHookEx_(myHook)
myHook =0
EndIf
EndProcedure
Procedure WindowCallback(WindowID.l, Message.l, wParam.l, lParam.l)
Shared myHook
If myHook > 0
Select wParam
Case #HSHELL_WINDOWCREATED: Debug "WINDOWCREATED: " + Str(WindowID) + " | " + Str(Message) + " | " + Str(wParam) + " | " + Str(lParam)
Case #HSHELL_WINDOWDESTROYED: Debug "WINDOWDESTROYED: " + Str(WindowID) + " | " + Str(Message) + " | " + Str(wParam) + " | " + Str(lParam)
EndSelect
EndIf
ProcedureReturn #PB_ProcessPureBasicEvents
EndProcedure
OpenWindow(0,250,250,250,250,#PB_Window_SystemMenu,"ShellHookTest")
CreateGadgetList(WindowID())
ButtonGadget(1,10,10,150,30,"Enable Hook")
SetWindowCallback(@WindowCallback())
Repeat
EventID = WaitWindowEvent()
Select EventID
Case #PB_EventGadget
If EventGadgetID() = 1
If GetGadgetText(1)="Disable Hook"
SetGadgetText(1,"Enable Hook")
HookProc(0)
Else
SetGadgetText(1,"Disable Hook")
HookProc(1)
EndIf
EndIf
EndSelect
Until EventID = #PB_EventCloseWindow
HookProc(0)
End
Code: Select all
ProcedureDLL ShellHook(nCode.l, wParam.l, lParam.l)
If nCode<0
ProcedureReturn CallNextHookEx_(@ShellHook, nCode, wParam, lParam)
EndIf
If wParam = #HSHELL_WINDOWCREATED Or wParam = #HSHELL_WINDOWDESTROYED
WindowName.s = "ShellHookTest"
ID = FindWindow_(#Null,@WindowName)
PostMessage_(ID, nCode, wParam, lParam)
EndIf
ProcedureReturn CallNextHookEx_(@ShellHook, nCode, wParam, lParam)
EndProcedure