Setwindowshookex wh_callwndproc delphi
To take advantage of a particular type of hook, the developer provides a hook procedure and uses the SetWindowsHookEx function to install it into the chain associated with the hook. A hook procedure must have the following syntax:. The nCode parameter is a hook code that the hook procedure uses to determine the action to perform. The value of the hook code depends on the type of the hook; each type has its own characteristic set of hook codes.
The values of the wParam and lParam parameters depend on the hook code, but they typically contain information about a message that was sent or posted. The SetWindowsHookEx function always installs a hook procedure at the beginning of a hook chain. When an event occurs that is monitored by a particular type of hook, the system calls the procedure at the beginning of the hook chain associated with the hook. Each hook procedure in the chain determines whether to pass the event to the next procedure.
A hook procedure passes an event to the next procedure by calling the CallNextHookEx function. Note that the hook procedures for some types of hooks can only monitor messages. A global hook monitors messages for all threads in the same desktop as the calling thread. A thread-specific hook monitors messages for only an individual thread. A global hook procedure can be called in the context of any application in the same desktop as the calling thread, so the procedure must be in a separate DLL module.
A thread-specific hook procedure is called only in the context of the associated thread. If an application installs a hook procedure for one of its own threads, the hook procedure can be in either the same module as the rest of the application's code or in a DLL. If the application installs a hook procedure for a thread of a different application, the procedure must be in a DLL.
For information, see Dynamic-Link Libraries. You should use global hooks only for debugging purposes; otherwise, you should avoid them. Global hooks hurt system performance and cause conflicts with other applications that implement the same type of global hook. Each type of hook enables an application to monitor a different aspect of the system's message-handling mechanism.
The following sections describe the available hooks. The structure contains the return value from the window procedure that processed the message, as well as the message parameters associated with the message. Msg, Message. Improve this question. Salvador Salvador First of all, you need a global hook if you're targeting other applications.
Then you'll need to keep track of window handles and window procedures of an application. You can't overwrite your window procedure pointer or window handle every time an application creates a window. You don't want that application's top level window messages to be delivered to an edit control window procedure for instance.. SertacAkyuz, this is just a basic sample to demostrate the issue, the real log dll keeps a list with the handles and windows proc.
Add a comment. Active Oldest Votes. In dll, the OS notifies your hook that a window is about to be created and you subclass the window procedure.
In project, InitWndProc is delivered the same message in which the window procedure is replaced with the MainWndProc method of the form. In dll, the re-replaced window procedure is never called again. Improve this answer. Sertac Akyuz Sertac Akyuz Thanks very much, For diagnose the cause of the issue. Do you have any workaround? Active Oldest Votes. Improve this answer. David Heffernan David Heffernan k 40 40 gold badges silver badges bronze badges.
Yes but what if i want to hook 5 different windows? Each belongs to a different class? In the end i just want to prevent focus stealing by these windows. If you can use WindowProc do so. If you must use SetWindowHookEx, hook the thread and then deal with each window as you please.
You'll hook every window proc call in the entire thread. Very hard for me to give specific advice for your app because I don't know what you are trying to achieve. I don't know what these windows are, who owns them and so on. Create; SomeClass. Create nil ; SomeClass. Depending on what you are hooking, pass something else instead of aHandle SomeClass. Do not forget to release the SubClass using: SomeClass. Pawel Piotrowski Pawel Piotrowski 51 2 2 silver badges 3 3 bronze badges.
And don't remember stdcall; modifier for WinAPI func. Komarov Andrey Komarov Andrey 13 3 3 bronze badges. Sign up or log in Sign up using Google. Sign up using Facebook.
0コメント