diff --git a/sdk-api-src/content/winuser/nf-winuser-setwindowshookexa.md b/sdk-api-src/content/winuser/nf-winuser-setwindowshookexa.md
index 0c3b8100e50..225dfcabd2d 100644
--- a/sdk-api-src/content/winuser/nf-winuser-setwindowshookexa.md
+++ b/sdk-api-src/content/winuser/nf-winuser-setwindowshookexa.md
@@ -2,7 +2,7 @@
UID: NF:winuser.SetWindowsHookExA
title: SetWindowsHookExA function (winuser.h)
description: Installs an application-defined hook procedure into a hook chain. (ANSI)
-helpviewer_keywords: ["SetWindowsHookExA", "WH_CALLWNDPROC", "WH_CALLWNDPROCRET", "WH_CBT", "WH_DEBUG", "WH_FOREGROUNDIDLE", "WH_GETMESSAGE", "WH_JOURNALPLAYBACK", "WH_JOURNALRECORD", "WH_KEYBOARD", "WH_KEYBOARD_LL", "WH_MOUSE", "WH_MOUSE_LL", "WH_MSGFILTER", "WH_SHELL", "WH_SYSMSGFILTER", "winuser/SetWindowsHookExA"]
+helpviewer_keywords: ["SetWindowsHookEx", "SetWindowsHookEx function [Windows and Messages]", "SetWindowsHookExA", "WH_CALLWNDPROC", "WH_CALLWNDPROCRET", "WH_CBT", "WH_DEBUG", "WH_FOREGROUNDIDLE", "WH_GETMESSAGE", "WH_JOURNALPLAYBACK", "WH_JOURNALRECORD", "WH_KEYBOARD", "WH_KEYBOARD_LL", "WH_MOUSE", "WH_MOUSE_LL", "WH_MSGFILTER", "WH_SHELL", "WH_SYSMSGFILTER", "_win32_SetWindowsHookEx", "_win32_setwindowshookex_cpp", "winmsg.setwindowshookex", "winui._win32_setwindowshookex", "winuser/SetWindowsHookEx", "winuser/SetWindowsHookExA"]
old-location: winmsg\setwindowshookex.htm
tech.root: winmsg
ms.assetid: VS|winui|~\winui\windowsuserinterface\windowing\hooks\hookreference\hookfunctions\setwindowshookex.htm
@@ -40,6 +40,7 @@ topic_type:
api_type:
- DllExport
api_location:
+ - ext-ms-win-rtcore-ntuser-window-ext-l1-1-1.dll
- ext-ms-win-ntuser-window-l1-1-6.dll
- ext-ms-win-ntuser-window-l1-1-5.dll
- User32.dll
@@ -59,7 +60,6 @@ req.apiset: ext-ms-win-ntuser-window-l1-1-0 (introduced in Windows 8)
# SetWindowsHookExA function
-
## -description
Installs an application-defined hook procedure into a hook chain. You would install a hook procedure to monitor the system for certain types of events. These events are associated either with a specific thread or with all threads in the same desktop as the calling thread.
@@ -70,7 +70,7 @@ Installs an application-defined hook procedure into a hook chain. You would inst
Type: int
-The type of hook procedure to be installed. This parameter can be one of the following values.
+The type of hook procedure to be installed. This parameter can be one of the following values.
@@ -96,7 +96,7 @@ Installs a hook procedure that monitors messages before the system sends them to
|
-
+
Installs a hook procedure that monitors messages after they have been processed by the destination window procedure. For more information, see the [HOOKPROC callback function](nc-winuser-hookproc.md) hook procedure.
|
@@ -108,7 +108,7 @@ Installs a hook procedure that monitors messages after they have been processed
-
+
Installs a hook procedure that receives notifications useful to a CBT application. For more information, see the [CBTProc](/windows/win32/winmsg/cbtproc) hook procedure.
|
@@ -133,7 +133,7 @@ Installs a hook procedure useful for debugging other hook procedures. For more i
-Installs a hook procedure that will be called when the application's foreground thread is about to become idle. This hook is useful for performing low priority tasks during idle time. For more information, see the [*ForegroundIdleProc*](/windows/win32/winmsg/foregroundidleproc) hook procedure.
+Installs a hook procedure that will be called when the application's foreground thread is about to become idle. This hook is useful for performing low priority tasks during idle time. For more information, see the [ForegroundIdleProc](/windows/win32/winmsg/foregroundidleproc) hook procedure.
|
@@ -145,7 +145,7 @@ Installs a hook procedure that will be called when the application's foreground
-Installs a hook procedure that monitors messages posted to a message queue. For more information, see the [*GetMsgProc*](/windows/win32/winmsg/getmsgproc) hook procedure.
+Installs a hook procedure that monitors messages posted to a message queue. For more information, see the [GetMsgProc](/windows/win32/winmsg/getmsgproc) hook procedure.
|
@@ -158,7 +158,7 @@ Installs a hook procedure that monitors messages posted to a message queue. For
> [!WARNING]
-> **Windows 11 and newer**: Journaling hook APIs are not supported. We recommend using the [**SendInput**](/windows/win32/api/winuser/nf-winuser-sendinput) TextInput API instead.
+> Journaling Hooks APIs are unsupported starting in Windows 11 and will be removed in a future release. Because of this, we highly recommend calling the [**SendInput**](/windows/win32/api/winuser/nf-winuser-sendinput) TextInput API instead.
Installs a hook procedure that posts messages previously recorded by a [WH_JOURNALRECORD](/windows/desktop/winmsg/about-hooks) hook procedure. For more information, see the [JournalPlaybackProc](/windows/win32/winmsg/journalplaybackproc) hook procedure.
@@ -173,7 +173,8 @@ Installs a hook procedure that posts messages previously recorded by a [WH_JOURN
|
> [!WARNING]
-> **Windows 11 and newer**: Journaling hook APIs are not supported. We recommend using the [**SendInput**](/windows/win32/api/winuser/nf-winuser-sendinput) TextInput API instead.
+> Journaling Hooks APIs are unsupported starting in Windows 11 and will be removed in a future release. Because of this, we highly recommend calling the [**SendInput**](/windows/win32/api/winuser/nf-winuser-sendinput) TextInput API instead.
+
Installs a hook procedure that records input messages posted to the system message queue. This hook is useful for recording macros. For more information, see the [JournalRecordProc](/windows/win32/winmsg/journalrecordproc) hook procedure.
@@ -198,8 +199,8 @@ Installs a hook procedure that monitors keystroke messages. For more information
|
-
-Installs a hook procedure that monitors low-level keyboard input events. For more information, see the LowLevelKeyboardProc hook procedure.
+
+Installs a hook procedure that monitors low-level keyboard input events. For more information, see the [LowLevelKeyboardProc](/windows/win32/winmsg/lowlevelkeyboardproc) hook procedure.
|
@@ -246,7 +247,7 @@ Installs a hook procedure that monitors messages generated as a result of an inp
-
+
Installs a hook procedure that receives notifications useful to shell applications. For more information, see the [ShellProc](/windows/win32/winmsg/shellproc) hook procedure.
|
@@ -287,7 +288,7 @@ The identifier of the thread with which the hook procedure is to be associated.
Type: HHOOK
-If the function succeeds, the return value is the handle to the hook procedure.
+If the function succeeds, the return value is the handle to the hook procedure.
If the function fails, the return value is NULL. To get extended error information, call [GetLastError](/windows/desktop/api/errhandlingapi/nf-errhandlingapi-getlasterror).
@@ -301,13 +302,15 @@ If a 64-bit application installs a global hook on 64-bit Windows, the 64-bit hoo
To hook all applications on the desktop of a 64-bit Windows installation, install a 32-bit global hook and a 64-bit global hook, each from appropriate processes, and be sure to keep pumping messages in the hooking application to avoid blocking normal functioning. If you already have a 32-bit global hooking application and it doesn't need to run in each application's context, you may not need to create a 64-bit version.
-An error may occur if the hMod parameter is NULL and the dwThreadId parameter is zero or specifies the identifier of a thread created by another process.
+An error may occur if the hMod parameter is NULL and the dwThreadId parameter is zero or specifies the identifier of a thread created by another process.
-Calling the [CallNextHookEx function](nf-winuser-callnexthookex.md) function to chain to the next hook procedure is optional, but it is highly recommended; otherwise, other applications that have installed hooks will not receive hook notifications and may behave incorrectly as a result. You should call CallNextHookEx unless you absolutely need to prevent the notification from being seen by other applications.
+Calling the [CallNextHookEx function](nf-winuser-callnexthookex.md) function to chain to the next hook procedure is optional, but it is highly recommended; otherwise, other applications that have installed hooks will not receive hook notifications and may behave incorrectly as a result. You should call CallNextHookEx unless you absolutely need to prevent the notification from being seen by other applications.
-Before terminating, an application must call the [UnhookWindowsHookEx function](nf-winuser-unhookwindowshookex.md) function to free system resources associated with the hook.
+In .NET apps, you must ensure the callback is not moved around by the garbage collector (otherwise your app will crash with an ExecutionEngineException). One way to do this is by making the callback a static method of your class.
-The scope of a hook depends on the hook type. Some hooks can be set only with global scope; others can also be set for only a specific thread, as shown in the following table.
+Before terminating, an application must call the [UnhookWindowsHookEx function](nf-winuser-unhookwindowshookex.md) function to free system resources associated with the hook.
+
+The scope of a hook depends on the hook type. Some hooks can be set only with global scope; others can also be set for only a specific thread, as shown in the following table.
@@ -378,9 +381,9 @@ The scope of a hook depends on the hook type. Some hooks can be set only with gl
For a specified hook type, thread hooks are called first, then global hooks. Be aware that the WH_MOUSE, WH_KEYBOARD, WH_JOURNAL*, WH_SHELL, and low-level hooks can be called on the thread that installed the hook rather than the thread processing the hook. For these hooks, it is possible that both the 32-bit and 64-bit hooks will be called if a 32-bit hook is ahead of a 64-bit hook in the hook chain.
-The global hooks are a shared resource, and installing one affects all applications in the same desktop as the calling thread. All global hook functions must be in libraries. Global hooks should be restricted to special-purpose applications or to use as a development aid during application debugging. Libraries that no longer need a hook should remove its hook procedure.
+The global hooks are a shared resource, and installing one affects all applications in the same desktop as the calling thread. All global hook functions must be in libraries. Global hooks should be restricted to special-purpose applications or to use as a development aid during application debugging. Libraries that no longer need a hook should remove its hook procedure.
-Windows Store app development If dwThreadId is zero, then window hook DLLs are not loaded in-process for the Windows Store app processes and the Windows Runtime broker process unless they are installed by either UIAccess processes (accessibility tools). The notification is delivered on the installer's thread for these hooks:
+Windows Store apps: If dwThreadId is zero, then window hook DLLs are not loaded in-process for the Windows Store app processes and the Windows Runtime broker process unless they are installed by either UIAccess processes (accessibility tools). The notification is delivered on the installer's thread for these hooks:
- WH_JOURNALPLAYBACK
@@ -400,13 +403,18 @@ The global hooks are a shared resource, and installing one affects all applicati
-This behavior is similar to what happens when there is an architecture mismatch between the hook DLL and the target application process, for example, when the hook DLL is 32-bit and the application process 64-bit.
+This behavior is similar to what happens when there is an architecture mismatch between the hook DLL and the target application process, for example, when the hook DLL is 32-bit and the application process 64-bit.
#### Examples
For an example, see [Installing and Releasing Hook Procedures](/windows/desktop/winmsg/using-hooks).
+
+
+
+
+
> [!NOTE]
> The winuser.h header defines SetWindowsHookEx as an alias that automatically selects the ANSI or Unicode version of this function based on the definition of the UNICODE preprocessor constant. Mixing usage of the encoding-neutral alias with code that is not encoding-neutral can lead to mismatches that result in compilation or runtime errors. For more information, see [Conventions for Function Prototypes](/windows/win32/intl/conventions-for-function-prototypes).
diff --git a/sdk-api-src/content/winuser/nf-winuser-setwindowshookexw.md b/sdk-api-src/content/winuser/nf-winuser-setwindowshookexw.md
index 776dba8e410..7db70924777 100644
--- a/sdk-api-src/content/winuser/nf-winuser-setwindowshookexw.md
+++ b/sdk-api-src/content/winuser/nf-winuser-setwindowshookexw.md
@@ -70,7 +70,7 @@ Installs an application-defined hook procedure into a hook chain. You would inst
Type: int
-The type of hook procedure to be installed. This parameter can be one of the following values.
+The type of hook procedure to be installed. This parameter can be one of the following values.
@@ -109,7 +109,7 @@ Installs a hook procedure that monitors messages after they have been processed
|
-Installs a hook procedure that receives notifications useful to a CBT application. For more information, see the CBTProc hook procedure.
+Installs a hook procedure that receives notifications useful to a CBT application. For more information, see the [CBTProc](/windows/win32/winmsg/cbtproc) hook procedure.
|
@@ -133,7 +133,7 @@ Installs a hook procedure useful for debugging other hook procedures. For more i
-Installs a hook procedure that will be called when the application's foreground thread is about to become idle. This hook is useful for performing low priority tasks during idle time. For more information, see the [ForegroundIdleProc](/windows/win32/winmsg/foregroundidleproc) hook procedure.
+Installs a hook procedure that will be called when the application's foreground thread is about to become idle. This hook is useful for performing low priority tasks during idle time. For more information, see the [ForegroundIdleProc](/windows/win32/winmsg/foregroundidleproc) hook procedure.
|
@@ -160,7 +160,7 @@ Installs a hook procedure that monitors messages posted to a message queue. For
> [!WARNING]
> Journaling Hooks APIs are unsupported starting in Windows 11 and will be removed in a future release. Because of this, we highly recommend calling the [**SendInput**](/windows/win32/api/winuser/nf-winuser-sendinput) TextInput API instead.
-Installs a hook procedure that posts messages previously recorded by a WH_JOURNALRECORD hook procedure. For more information, see the [JournalPlaybackProc](/windows/win32/winmsg/journalplaybackproc) hook procedure.
+Installs a hook procedure that posts messages previously recorded by a [WH_JOURNALRECORD](/windows/desktop/winmsg/about-hooks) hook procedure. For more information, see the [JournalPlaybackProc](/windows/win32/winmsg/journalplaybackproc) hook procedure.
@@ -188,7 +188,7 @@ Installs a hook procedure that records input messages posted to the system messa
-Installs a hook procedure that monitors keystroke messages. For more information, see the KeyboardProc hook procedure.
+Installs a hook procedure that monitors keystroke messages. For more information, see the [KeyboardProc](/windows/win32/winmsg/keyboardproc) hook procedure.
|
@@ -212,7 +212,7 @@ Installs a hook procedure that monitors low-level keyboard input events. For mor
-Installs a hook procedure that monitors mouse messages. For more information, see the MouseProc hook procedure.
+Installs a hook procedure that monitors mouse messages. For more information, see the [MouseProc](/windows/win32/winmsg/mouseproc) hook procedure.
|
@@ -223,7 +223,8 @@ Installs a hook procedure that monitors mouse messages. For more information, se
-Installs a hook procedure that monitors low-level mouse input events. For more information, see the LowLevelMouseProc hook procedure.
+
+Installs a hook procedure that monitors low-level mouse input events. For more information, see the [LowLevelMouseProc](/windows/win32/winmsg/lowlevelmouseproc) hook procedure.
|
@@ -235,7 +236,7 @@ Installs a hook procedure that monitors low-level mouse input events. For more i
-Installs a hook procedure that monitors messages generated as a result of an input event in a dialog box, message box, menu, or scroll bar. For more information, see the MessageProc hook procedure.
+Installs a hook procedure that monitors messages generated as a result of an input event in a dialog box, message box, menu, or scroll bar. For more information, see the [MessageProc](/windows/win32/winmsg/messageproc) hook procedure.
|
@@ -247,7 +248,7 @@ Installs a hook procedure that monitors messages generated as a result of an inp
-Installs a hook procedure that receives notifications useful to shell applications. For more information, see the ShellProc hook procedure.
+Installs a hook procedure that receives notifications useful to shell applications. For more information, see the [ShellProc](/windows/win32/winmsg/shellproc) hook procedure.
|
@@ -258,7 +259,9 @@ Installs a hook procedure that receives notifications useful to shell applicatio
-Installs a hook procedure that monitors messages generated as a result of an input event in a dialog box, message box, menu, or scroll bar. The hook procedure monitors these messages for all applications in the same desktop as the calling thread. For more information, see the SysMsgProc hook procedure.
+
+Installs a hook procedure that monitors messages generated as a result of an input event in a dialog box, message box, menu, or scroll bar. The hook procedure monitors these messages for all applications in the same desktop as the calling thread. For more information, see the [SysMsgProc](/windows/win32/winmsg/sysmsgproc) hook procedure.
+
|
@@ -285,9 +288,9 @@ The identifier of the thread with which the hook procedure is to be associated.
Type: HHOOK
-If the function succeeds, the return value is the handle to the hook procedure.
+If the function succeeds, the return value is the handle to the hook procedure.
-If the function fails, the return value is NULL. To get extended error information, call GetLastError.
+If the function fails, the return value is NULL. To get extended error information, call [GetLastError](/windows/desktop/api/errhandlingapi/nf-errhandlingapi-getlasterror).
## -remarks
@@ -299,13 +302,13 @@ If a 64-bit application installs a global hook on 64-bit Windows, the 64-bit hoo
To hook all applications on the desktop of a 64-bit Windows installation, install a 32-bit global hook and a 64-bit global hook, each from appropriate processes, and be sure to keep pumping messages in the hooking application to avoid blocking normal functioning. If you already have a 32-bit global hooking application and it doesn't need to run in each application's context, you may not need to create a 64-bit version.
-An error may occur if the hMod parameter is NULL and the dwThreadId parameter is zero or specifies the identifier of a thread created by another process.
+An error may occur if the hMod parameter is NULL and the dwThreadId parameter is zero or specifies the identifier of a thread created by another process.
Calling the [CallNextHookEx function](nf-winuser-callnexthookex.md) function to chain to the next hook procedure is optional, but it is highly recommended; otherwise, other applications that have installed hooks will not receive hook notifications and may behave incorrectly as a result. You should call CallNextHookEx unless you absolutely need to prevent the notification from being seen by other applications.
In .NET apps, you must ensure the callback is not moved around by the garbage collector (otherwise your app will crash with an ExecutionEngineException). One way to do this is by making the callback a static method of your class.
-Before terminating, an application must call the [UnhookWindowsHookEx function](nf-winuser-unhookwindowshookex.md) function to free system resources associated with the hook.
+Before terminating, an application must call the [UnhookWindowsHookEx function](nf-winuser-unhookwindowshookex.md) function to free system resources associated with the hook.
The scope of a hook depends on the hook type. Some hooks can be set only with global scope; others can also be set for only a specific thread, as shown in the following table.
@@ -375,11 +378,10 @@ The scope of a hook depends on the hook type. Some hooks can be set only with gl
Global only |
-
For a specified hook type, thread hooks are called first, then global hooks. Be aware that the WH_MOUSE, WH_KEYBOARD, WH_JOURNAL*, WH_SHELL, and low-level hooks can be called on the thread that installed the hook rather than the thread processing the hook. For these hooks, it is possible that both the 32-bit and 64-bit hooks will be called if a 32-bit hook is ahead of a 64-bit hook in the hook chain.
-The global hooks are a shared resource, and installing one affects all applications in the same desktop as the calling thread. All global hook functions must be in libraries. Global hooks should be restricted to special-purpose applications or to use as a development aid during application debugging. Libraries that no longer need a hook should remove its hook procedure.
+The global hooks are a shared resource, and installing one affects all applications in the same desktop as the calling thread. All global hook functions must be in libraries. Global hooks should be restricted to special-purpose applications or to use as a development aid during application debugging. Libraries that no longer need a hook should remove its hook procedure.
Windows Store apps: If dwThreadId is zero, then window hook DLLs are not loaded in-process for the Windows Store app processes and the Windows Runtime broker process unless they are installed by either UIAccess processes (accessibility tools). The notification is delivered on the installer's thread for these hooks:
@@ -401,12 +403,12 @@ The global hooks are a shared resource, and installing one affects all applicati
-This behavior is similar to what happens when there is an architecture mismatch between the hook DLL and the target application process, for example, when the hook DLL is 32-bit and the application process 64-bit.
+This behavior is similar to what happens when there is an architecture mismatch between the hook DLL and the target application process, for example, when the hook DLL is 32-bit and the application process 64-bit.
#### Examples
-For an example, see Installing and Releasing Hook Procedures.
+For an example, see [Installing and Releasing Hook Procedures](/windows/desktop/winmsg/using-hooks).