WinSetHook: Difference between revisions
Appearance
No edit summary |
No edit summary |
||
Line 37: | Line 37: | ||
See LockupHook | See LockupHook | ||
:;HK_MSGCONTROL | :;HK_MSGCONTROL | ||
See MsgControlHook | See [[MsgControlHook]] | ||
:;HK_MSGFILTER | :;HK_MSGFILTER | ||
See MsgFilterHook | See MsgFilterHook |
Latest revision as of 19:38, 9 April 2025
This function installs an application procedure into a specified hook chain.
Syntax
WinSetHook(hab, hmq, lHookType, pHookProc, Module)
Parameters
- hab (HAB) - input
- Anchor-block handle.
- hmq (HMQ) - input
- Queue identity.
- This parameter identifies the queue to which the hook chain belongs. If hmq is set to NULLHANDLE, the hook is installed in the system hook chain. If hmq is set to HMQ_CURRENT, the hook is installed in the message queue associated with the current thread (calling thread).
- lHookType (LONG) - input
- Hook-chain type.
- HK_CHECKMSGFILTER
See CheckMsgFilterHook
- HK_CODEPAGECHANGED
See CodePageChangedHook
- HK_DESTROYWINDOW
See DestroyWindowHook
- HK_FINDWORD
See FindWordHook
- HK_FLUSHBUF
See FlushBufHook
- HK_HELP
See HelpHook
- HK_INPUT
See InputHook
- HK_JOURNALPLAYBACK
See JournalPlaybackHook
- HK_JOURNALRECORD
See JournalRecordHook
- HK_LOADER
See LoaderHook
- HK_LOCKUP
See LockupHook
- HK_MSGCONTROL
See MsgControlHook
- HK_MSGFILTER
See MsgFilterHook
- HK_MSGINPUT
See MsgInputHook
- HK_PLIST_ENTRY
See ProgramListEntryHook
- HK_PLIST_EXIT
See ProgramListExitHook
- HK_REGISTERUSERMSG
See RegisterUserHook
- HK_SENDMSG
See SendMsgHook
- HK_WINDOWDC
See WindowDCHook
- pHookProc (PFN) - input
- Address of the application hook procedure.
- Module (HMODULE) - input
- Resource identity.
- Handle of the module that contains the application hook procedure, as returned by the DosLoadModule or DosQueryModuleHandle call. This parameter can be NULLHANDLE when a queue hook is being installed by an application into its own message queue.
- When hooking a system hook this parameter must be a valid module handle.
Returns
- rc (BOOL) - returns
- Success indicator.
- TRUE
- Successful completion
- FALSE
- An error occurred.
Errors
Possible returns from WinGetLastError
- PMERR_INVALID_HMQ (0x1002)
- An invalid message-queue handle was specified.
- PMERR_PARAMETER_OUT_OF_RANGE (0x1003)
- The value of a parameter was not within the defined valid range for that parameter.
Remarks
Queue hooks are called before system hooks.
This function installs the hook at the head of either the system or queue chain. The most recently installed hook is called first.
Use the WinQueryWindowULong function to obtain the queue handle associated with a window handle.
Example Code
This example uses the WinSetHook call to intercept user-input messages from the application queue.
#define INCL_WINHOOKS #include <OS2.H> void RecordHook(HAB hab, PQMSG pqmsg); /* prototype of hook */ /* procedure. */ samp() { HAB hab; WinSetHook(hab, HMQ_CURRENT, HK_JOURNALRECORD, (PFN)RecordHook, (HMODULE)0); /* hook is into application queue. */ WinReleaseHook(hab, HMQ_CURRENT, HK_JOURNALRECORD, (PFN)RecordHook, (HMODULE)0); /* hook is into application queue, */ } /* This hook records user-input messages. */ void RecordHook(HAB hab, PQMSG pqmsg) { /* ... */ }
Definition
#define INCL_WINHOOKS /* Or use INCL_WIN, INCL_PM, */ #include <os2.h> HAB hab; /* Anchor-block handle. */ HMQ hmq; /* Queue identity. */ LONG lHookType; /* Hook-chain type. */ PFN pHookProc; /* Address of the application hook procedure. */ HMODULE Module; /* Resource identity. */ BOOL rc; /* Success indicator. */ rc = WinSetHook(hab, hmq, lHookType, pHookProc, Module);
Related Functions
- WinCallMsgFilter
- WinReleaseHook