using System;
using System.Runtime.InteropServices;
namespace Vanara.PInvoke
{
public static partial class User32
{
/// The delegate for a hook procedure set by SetWindowsHookEx.
///
/// 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 value depends on the hook code, but typically contains information about a message that was sent or posted.
///
///
/// The value depends on the hook code, but typically contains information about a message that was sent or posted.
///
/// The value depends on the hook code.
[PInvokeData("WinUser.h")]
[UnmanagedFunctionPointer(CallingConvention.Winapi)]
public delegate IntPtr HookProc(int nCode, IntPtr wParam, IntPtr lParam);
///
///
/// An application-defined callback (or hook) function that the system calls in response to events generated by an accessible
/// object. The hook function processes the event notifications as required. Clients install the hook function and request specific
/// types of event notifications by calling SetWinEventHook.
///
///
/// The WINEVENTPROC type defines a pointer to this callback function. WinEventProc is a placeholder for the application-defined
/// function name.
///
///
///
/// Type: HWINEVENTHOOK
///
/// Handle to an event hook function. This value is returned by SetWinEventHook when the hook function is installed and is specific
/// to each instance of the hook function.
///
///
///
/// Type: DWORD
/// Specifies the event that occurred. This value is one of the event constants.
///
///
/// Type: HWND
///
/// Handle to the window that generates the event, or NULL if no window is associated with the event. For example, the mouse
/// pointer is not associated with a window.
///
///
///
/// Type: LONG
/// Identifies the object associated with the event. This is one of the object identifiers or a custom object ID.
///
///
/// Type: LONG
///
/// Identifies whether the event was triggered by an object or a child element of the object. If this value is CHILDID_SELF, the
/// event was triggered by the object; otherwise, this value is the child ID of the element that triggered the event.
///
///
/// The identifier event thread.
///
/// Type: DWORD
/// Specifies the time, in milliseconds, that the event was generated.
///
///
/// Within the hook function, the parameters hwnd, idObject, and idChild are used when calling AccessibleObjectFromEvent.
/// Servers generate events by calling NotifyWinEvent.
/// Create multiple callback functions to handle different events. For more information, see Registering a Hook Function.
///
// https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nc-winuser-wineventproc WINEVENTPROC Wineventproc; void
// Wineventproc( HWINEVENTHOOK hWinEventHook, DWORD event, HWND hwnd, LONG idObject, LONG idChild, DWORD idEventThread, DWORD
// dwmsEventTime ) {...}
[PInvokeData("winuser.h", MSDNShortId = "5fe3cacc-4563-43da-960d-729d3fe4ff70")]
[UnmanagedFunctionPointer(CallingConvention.Winapi)]
public delegate void WinEventProc(HWINEVENTHOOK hWinEventHook, uint winEvent, HWND hwnd, int idObject, int idChild, uint idEventThread, uint dwmsEventTime);
/// The type of hook procedure to be installed.
[PInvokeData("WinUser.h", MSDNShortId = "ms644990")]
public enum HookType
{
///
/// 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.
///
WH_MSGFILTER = -1,
///
/// 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 hook procedure.
///
WH_JOURNALRECORD = 0,
///
/// Installs a hook procedure that posts messages previously recorded by a WH_JOURNALRECORD hook procedure. For more
/// information, see the JournalPlaybackProc hook procedure.
///
WH_JOURNALPLAYBACK = 1,
///
/// Installs a hook procedure that monitors keystroke messages. For more information, see the KeyboardProc hook procedure.
///
WH_KEYBOARD = 2,
///
/// Installs a hook procedure that monitors messages posted to a message queue. For more information, see the GetMsgProc hook procedure.
///
WH_GETMESSAGE = 3,
///
/// Installs a hook procedure that monitors messages before the system sends them to the destination window procedure. For more
/// information, see the CallWndProc hook procedure.
///
WH_CALLWNDPROC = 4,
///
/// Installs a hook procedure that receives notifications useful to a CBT application. For more information, see the CBTProc
/// hook procedure.
///
WH_CBT = 5,
///
/// 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.
///
WH_SYSMSGFILTER = 6,
/// Installs a hook procedure that monitors mouse messages. For more information, see the MouseProc hook procedure.
WH_MOUSE = 7,
///
WH_HARDWARE = 8,
///
/// Installs a hook procedure useful for debugging other hook procedures. For more information, see the DebugProc hook procedure.
///
WH_DEBUG = 9,
///
/// Installs a hook procedure that receives notifications useful to shell applications. For more information, see the ShellProc
/// hook procedure.
///
WH_SHELL = 10,
///
/// 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 hook procedure.
///
WH_FOREGROUNDIDLE = 11,
///
/// Installs a hook procedure that monitors messages after they have been processed by the destination window procedure. For
/// more information, see the CallWndRetProc hook procedure.
///
WH_CALLWNDPROCRET = 12,
///
/// Installs a hook procedure that monitors low-level keyboard input events. For more information, see the LowLevelKeyboardProc
/// hook procedure.
///
WH_KEYBOARD_LL = 13,
///
/// Installs a hook procedure that monitors low-level mouse input events. For more information, see the LowLevelMouseProc hook procedure.
///
WH_MOUSE_LL = 14
}
/// Flags for .
[PInvokeData("winuser.h", MSDNShortId = "090bda1b-0635-4aa3-ae33-3987b36e30b8")]
[Flags]
public enum WINEVENT
{
///
/// The DLL that contains the callback function is mapped into the address space of the process that generates the event. With
/// this flag, the system sends event notifications to the callback function as they occur. The hook function must be in a DLL
/// when this flag is specified. This flag has no effect when both the calling process and the generating process are not 32-bit
/// or 64-bit processes, or when the generating process is a console application. For more information, see In-Context Hook Functions.
///
WINEVENT_INCONTEXT = 0,
///
/// The callback function is not mapped into the address space of the process that generates the event. Because the hook
/// function is called across process boundaries, the system must queue events. Although this method is asynchronous, events are
/// guaranteed to be in sequential order. For more information, see Out-of-Context Hook Functions.
///
WINEVENT_OUTOFCONTEXT = 1,
///
/// Prevents this instance of the hook from receiving the events that are generated by threads in this process. This flag does
/// not prevent threads from generating events.
///
WINEVENT_SKIPOWNPROCESS = 2,
///
/// Prevents this instance of the hook from receiving the events that are generated by the thread that is registering this hook.
///
WINEVENT_SKIPOWNTHREAD = 4,
}
///
///
/// Passes the specified message and hook code to the hook procedures associated with the WH_SYSMSGFILTER and WH_MSGFILTER hooks. A
/// WH_SYSMSGFILTER or WH_MSGFILTER hook procedure is an application-defined callback function that examines and,
/// optionally, modifies messages for a dialog box, message box, menu, or scroll bar.
///
///
///
/// Type: LPMSG
/// A pointer to an MSG structure that contains the message to be passed to the hook procedures.
///
///
/// Type: int
///
/// An application-defined code used by the hook procedure to determine how to process the message. The code must not have the same
/// value as system-defined hook codes (MSGF_ and HC_) associated with the WH_SYSMSGFILTER and WH_MSGFILTER hooks.
///
///
///
/// Type: Type: BOOL
/// If the application should process the message further, the return value is zero.
/// If the application should not process the message further, the return value is nonzero.
///
///
///
/// The system calls CallMsgFilter to enable applications to examine and control the flow of messages during internal
/// processing of dialog boxes, message boxes, menus, and scroll bars, or when the user activates a different window by pressing the
/// ALT+TAB key combination.
///
/// Install this hook procedure by using the SetWindowsHookEx function.
/// Examples
/// For an example, see WH_MSGFILTER and WH_SYSMSGFILTER Hooks.
///
// https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-callmsgfiltera BOOL CallMsgFilterA( LPMSG lpMsg, int
// nCode );
[DllImport(Lib.User32, SetLastError = false, CharSet = CharSet.Auto)]
[PInvokeData("winuser.h", MSDNShortId = "callmsgfilter")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool CallMsgFilter(ref MSG lpMsg, int nCode);
///
///
/// Passes the hook information to the next hook procedure in the current hook chain. A hook procedure can call this function either
/// before or after processing the hook information.
///
///
///
/// Type: HHOOK
/// This parameter is ignored.
///
///
/// Type: int
///
/// The hook code passed to the current hook procedure. The next hook procedure uses this code to determine how to process the hook information.
///
///
///
/// Type: WPARAM
///
/// The wParam value passed to the current hook procedure. The meaning of this parameter depends on the type of hook associated with
/// the current hook chain.
///
///
///
/// Type: LPARAM
///
/// The lParam value passed to the current hook procedure. The meaning of this parameter depends on the type of hook associated with
/// the current hook chain.
///
///
///
/// Type: Type: LRESULT
///
/// This value is returned by the next hook procedure in the chain. The current hook procedure must also return this value. The
/// meaning of the return value depends on the hook type. For more information, see the descriptions of the individual hook procedures.
///
///
///
/// Hook procedures are installed in chains for particular hook types. CallNextHookEx calls the next hook in the chain.
///
/// Calling CallNextHookEx 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.
///
///
// https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-callnexthookex LRESULT CallNextHookEx( HHOOK hhk, int
// nCode, WPARAM wParam, LPARAM lParam );
[DllImport(Lib.User32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("winuser.h", MSDNShortId = "callnexthookex")]
public static extern IntPtr CallNextHookEx(HHOOK hhk, int nCode, IntPtr wParam, IntPtr lParam);
/// Determines whether there is an installed WinEvent hook that might be notified of a specified event.
///
/// Type: DWORD
///
/// The event constant that hooks might be notified of. The function checks whether there is an installed hook for this event constant.
///
///
///
/// Type: BOOL
/// If there is a hook to be notified of the specified event, the return value is TRUE.
/// If there are no hooks to be notified of the specified event, the return value is FALSE.
///
///
///
/// This method is guaranteed to never return a false negative. If this method returns FALSE, it means that no hooks in the
/// system would be notified of the event. However, this method may return a false positive. In other words, it may return
/// TRUE even though there are no hooks that would be notified. Thus, it is safe for components to circumvent some work if
/// this method returns FALSE.
///
/// Event hooks can be installed at any time, so server developers should not cache the return value for long periods of time.
///
// https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-iswineventhookinstalled BOOL IsWinEventHookInstalled(
// DWORD event );
[DllImport(Lib.User32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("winuser.h", MSDNShortId = "bc1e97ad-748d-420a-8c9a-72a555b685e1")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool IsWinEventHookInstalled(uint winEvent);
///
///
/// 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.
///
///
///
/// Type: int
/// The type of hook procedure to be installed. This parameter can be one of the following values.
///
///
/// Value
/// Meaning
///
/// -
/// WH_CALLWNDPROC 4
///
/// Installs a hook procedure that monitors messages before the system sends them to the destination window procedure. For more
/// information, see the CallWndProc hook procedure.
///
///
/// -
/// WH_CALLWNDPROCRET 12
///
/// Installs a hook procedure that monitors messages after they have been processed by the destination window procedure. For more
/// information, see the CallWndRetProc hook procedure.
///
///
/// -
/// WH_CBT 5
///
/// Installs a hook procedure that receives notifications useful to a CBT application. For more information, see the CBTProc hook procedure.
///
///
/// -
/// WH_DEBUG 9
/// Installs a hook procedure useful for debugging other hook procedures. For more information, see the DebugProc hook procedure.
///
/// -
/// WH_FOREGROUNDIDLE 11
///
/// 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 hook procedure.
///
///
/// -
/// WH_GETMESSAGE 3
///
/// Installs a hook procedure that monitors messages posted to a message queue. For more information, see the GetMsgProc hook procedure.
///
///
/// -
/// WH_JOURNALPLAYBACK 1
///
/// Installs a hook procedure that posts messages previously recorded by a WH_JOURNALRECORD hook procedure. For more information,
/// see the JournalPlaybackProc hook procedure.
///
///
/// -
/// WH_JOURNALRECORD 0
///
/// 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 hook procedure.
///
///
/// -
/// WH_KEYBOARD 2
/// Installs a hook procedure that monitors keystroke messages. For more information, see the KeyboardProc hook procedure.
///
/// -
/// WH_KEYBOARD_LL 13
///
/// Installs a hook procedure that monitors low-level keyboard input events. For more information, see the LowLevelKeyboardProc hook procedure.
///
///
/// -
/// WH_MOUSE 7
/// Installs a hook procedure that monitors mouse messages. For more information, see the MouseProc hook procedure.
///
/// -
/// WH_MOUSE_LL 14
///
/// Installs a hook procedure that monitors low-level mouse input events. For more information, see the LowLevelMouseProc hook procedure.
///
///
/// -
/// WH_MSGFILTER -1
///
/// 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.
///
///
/// -
/// WH_SHELL 10
///
/// Installs a hook procedure that receives notifications useful to shell applications. For more information, see the ShellProc hook procedure.
///
///
/// -
/// WH_SYSMSGFILTER 6
///
/// 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.
///
///
///
///
///
/// Type: HOOKPROC
///
/// A pointer to the hook procedure. If the dwThreadId parameter is zero or specifies the identifier of a thread created by a
/// different process, the lpfn parameter must point to a hook procedure in a DLL. Otherwise, lpfn can point to a hook procedure in
/// the code associated with the current process.
///
///
///
/// Type: HINSTANCE
///
/// A handle to the DLL containing the hook procedure pointed to by the lpfn parameter. The hMod parameter must be set to
/// NULL if the dwThreadId parameter specifies a thread created by the current process and if the hook procedure is within
/// the code associated with the current process.
///
///
///
/// Type: DWORD
///
/// The identifier of the thread with which the hook procedure is to be associated. For desktop apps, if this parameter is zero, the
/// hook procedure is associated with all existing threads running in the same desktop as the calling thread. For Windows Store
/// apps, see the Remarks section.
///
///
///
/// Type: Type: HHOOK
/// 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.
///
///
///
/// SetWindowsHookEx can be used to inject a DLL into another process. A 32-bit DLL cannot be injected into a 64-bit process,
/// and a 64-bit DLL cannot be injected into a 32-bit process. If an application requires the use of hooks in other processes, it is
/// required that a 32-bit application call SetWindowsHookEx to inject a 32-bit DLL into 32-bit processes, and a 64-bit
/// application call SetWindowsHookEx to inject a 64-bit DLL into 64-bit processes. The 32-bit and 64-bit DLLs must have
/// different names.
///
///
/// Because hooks run in the context of an application, they must match the "bitness" of the application. If a 32-bit application
/// installs a global hook on 64-bit Windows, the 32-bit hook is injected into each 32-bit process (the usual security boundaries
/// apply). In a 64-bit process, the threads are still marked as "hooked." However, because a 32-bit application must run the hook
/// code, the system executes the hook in the hooking app's context; specifically, on the thread that called
/// SetWindowsHookEx. This means that the hooking application must continue to pump messages or it might block the normal
/// functioning of the 64-bit processes.
///
///
/// If a 64-bit application installs a global hook on 64-bit Windows, the 64-bit hook is injected into each 64-bit process, while
/// all 32-bit processes use a callback to the hooking application.
///
///
/// 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.
///
///
/// Calling the CallNextHookEx 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 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.
///
///
///
/// Hook
/// Scope
///
/// -
/// WH_CALLWNDPROC
/// Thread or global
///
/// -
/// WH_CALLWNDPROCRET
/// Thread or global
///
/// -
/// WH_CBT
/// Thread or global
///
/// -
/// WH_DEBUG
/// Thread or global
///
/// -
/// WH_FOREGROUNDIDLE
/// Thread or global
///
/// -
/// WH_GETMESSAGE
/// Thread or global
///
/// -
/// WH_JOURNALPLAYBACK
/// Global only
///
/// -
/// WH_JOURNALRECORD
/// Global only
///
/// -
/// WH_KEYBOARD
/// Thread or global
///
/// -
/// WH_KEYBOARD_LL
/// Global only
///
/// -
/// WH_MOUSE
/// Thread or global
///
/// -
/// WH_MOUSE_LL
/// Global only
///
/// -
/// WH_MSGFILTER
/// Thread or global
///
/// -
/// WH_SHELL
/// Thread or global
///
/// -
/// WH_SYSMSGFILTER
/// 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.
///
///
/// 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:
///
///
/// -
/// WH_JOURNALPLAYBACK
///
/// -
/// WH_JOURNALRECORD
///
/// -
/// WH_KEYBOARD
///
/// -
/// WH_KEYBOARD_LL
///
/// -
/// WH_MOUSE
///
/// -
/// WH_MOUSE_LL
///
///
///
/// 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.
///
// https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-setwindowshookexa HHOOK SetWindowsHookExA( int idHook,
// HOOKPROC lpfn, HINSTANCE hmod, DWORD dwThreadId );
[DllImport(Lib.User32, SetLastError = true, CharSet = CharSet.Auto)]
[PInvokeData("winuser.h", MSDNShortId = "setwindowshookex")]
public static extern SafeHHOOK SetWindowsHookEx(HookType idHook, HookProc lpfn, HINSTANCE hmod, int dwThreadId);
/// Sets an event hook function for a range of events.
///
/// Type: UINT
///
/// Specifies the event constant for the lowest event value in the range of events that are handled by the hook function. This
/// parameter can be set to EVENT_MIN to indicate the lowest possible event value. See for
/// defined values.
///
///
///
/// Type: UINT
///
/// Specifies the event constant for the highest event value in the range of events that are handled by the hook function. This
/// parameter can be set to EVENT_MAX to indicate the highest possible event value. See for defined values.
///
///
///
/// Type: HMODULE
///
/// Handle to the DLL that contains the hook function at lpfnWinEventProc, if the WINEVENT_INCONTEXT flag is specified in the
/// dwFlags parameter. If the hook function is not located in a DLL, or if the WINEVENT_OUTOFCONTEXT flag is specified, this
/// parameter is NULL.
///
///
///
/// Type: WINEVENTPROC
/// Pointer to the event hook function. For more information about this function, see WinEventProc.
///
///
/// Type: DWORD
///
/// Specifies the ID of the process from which the hook function receives events. Specify zero (0) to receive events from all
/// processes on the current desktop.
///
///
///
/// Type: DWORD
///
/// Specifies the ID of the thread from which the hook function receives events. If this parameter is zero, the hook function is
/// associated with all existing threads on the current desktop.
///
///
///
/// Type: UINT
/// Flag values that specify the location of the hook function and of the events to be skipped. The following flags are valid:
///
///
/// Value
/// Meaning
///
/// -
/// WINEVENT_INCONTEXT
///
/// The DLL that contains the callback function is mapped into the address space of the process that generates the event. With this
/// flag, the system sends event notifications to the callback function as they occur. The hook function must be in a DLL when this
/// flag is specified. This flag has no effect when both the calling process and the generating process are not 32-bit or 64-bit
/// processes, or when the generating process is a console application. For more information, see In-Context Hook Functions.
///
///
/// -
/// WINEVENT_OUTOFCONTEXT
///
/// The callback function is not mapped into the address space of the process that generates the event. Because the hook function is
/// called across process boundaries, the system must queue events. Although this method is asynchronous, events are guaranteed to
/// be in sequential order. For more information, see Out-of-Context Hook Functions.
///
///
/// -
/// WINEVENT_SKIPOWNPROCESS
///
/// Prevents this instance of the hook from receiving the events that are generated by threads in this process. This flag does not
/// prevent threads from generating events.
///
///
/// -
/// WINEVENT_SKIPOWNTHREAD
///
/// Prevents this instance of the hook from receiving the events that are generated by the thread that is registering this hook.
///
///
///
/// The following flag combinations are valid:
///
/// -
/// WINEVENT_INCONTEXT | WINEVENT_SKIPOWNPROCESS
///
/// -
/// WINEVENT_INCONTEXT | WINEVENT_SKIPOWNTHREAD
///
/// -
/// WINEVENT_OUTOFCONTEXT | WINEVENT_SKIPOWNPROCESS
///
/// -
/// WINEVENT_OUTOFCONTEXT | WINEVENT_SKIPOWNTHREAD
///
///
/// Additionally, client applications can specify WINEVENT_INCONTEXT, or WINEVENT_OUTOFCONTEXT alone.
/// See Remarks section for information on Windows Store app development.
///
///
/// Type: HWINEVENTHOOK
///
/// If successful, returns an HWINEVENTHOOK value that identifies this event hook instance. Applications save this return value to
/// use it with the UnhookWinEvent function.
///
/// If unsuccessful, returns zero.
///
///
/// This function allows clients to specify which processes and threads they are interested in.
///
/// If the idProcess parameter is nonzero and idThread is zero, the hook function receives the specified events from all threads in
/// that process. If the idProcess parameter is zero and idThread is nonzero, the hook function receives the specified events only
/// from the thread specified by idThread. If both are zero, the hook function receives the specified events from all threads and processes.
///
///
/// Clients can call SetWinEventHook multiple times if they want to register additional hook functions or listen for
/// additional events.
///
/// The client thread that calls SetWinEventHook must have a message loop in order to receive events.
///
/// When you use SetWinEventHook to set a callback in managed code, you should use the GCHandle structure to avoid
/// exceptions. This tells the garbage collector not to move the callback.
///
///
/// For out-of-context events, the event is delivered on the same thread that called SetWinEventHook. In some situations,
/// even if you request WINEVENT_INCONTEXT events, the events will still be delivered out-of-context. These scenarios include events
/// from console windows and events from processes that have a different bit-depth (64 bit versus 32 bits) than the caller.
///
///
/// While a hook function processes an event, additional events may be triggered, which may cause the hook function to reenter
/// before the processing for the original event is finished. The problem with reentrancy in hook functions is that events are
/// completed out of sequence unless the hook function handles this situation. For more information, see Guarding Against Reentrancy.
///
///
/// Windows Store app development If dwFlags is WINEVENT_INCONTEXT AND (idProcess = 0 | idThread = 0), 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 UIAccess processes (accessibility tools). The notification is delivered on the installer's thread.
///
///
/// 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
///
/// The following example code shows how a client application might listen for menu-start and menu-end events. For simplicity, the
/// event handler just sends some information to the standard output.
///
///
// https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-setwineventhook HWINEVENTHOOK SetWinEventHook( DWORD
// eventMin, DWORD eventMax, HMODULE hmodWinEventProc, WINEVENTPROC pfnWinEventProc, DWORD idProcess, DWORD idThread, DWORD dwFlags );
[DllImport(Lib.User32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("winuser.h", MSDNShortId = "090bda1b-0635-4aa3-ae33-3987b36e30b8")]
public static extern HWINEVENTHOOK SetWinEventHook(uint eventMin, uint eventMax, HINSTANCE hmodWinEventProc, WinEventProc pfnWinEventProc, uint idProcess, uint idThread, WINEVENT dwFlags);
///
/// Removes a hook procedure installed in a hook chain by the SetWindowsHookEx function.
///
///
/// Type: HHOOK
/// A handle to the hook to be removed. This parameter is a hook handle obtained by a previous call to SetWindowsHookEx.
///
///
/// Type: Type: BOOL
/// If the function succeeds, the return value is nonzero.
/// If the function fails, the return value is zero. To get extended error information, call GetLastError.
///
///
///
/// The hook procedure can be in the state of being called by another thread even after UnhookWindowsHookEx returns. If the
/// hook procedure is not being called concurrently, the hook procedure is removed immediately before UnhookWindowsHookEx returns.
///
/// Examples
/// For an example, see Monitoring System Events.
///
// https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-unhookwindowshookex BOOL UnhookWindowsHookEx( HHOOK hhk );
[DllImport(Lib.User32, SetLastError = true, ExactSpelling = true)]
[PInvokeData("winuser.h", MSDNShortId = "unhookwindowshookex")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool UnhookWindowsHookEx(HHOOK hhk);
/// Removes an event hook function created by a previous call to SetWinEventHook.
///
/// Type: HWINEVENTHOOK
/// Handle to the event hook returned in the previous call to SetWinEventHook.
///
///
/// Type: BOOL
/// If successful, returns TRUE; otherwise, returns FALSE.
/// Three common errors cause this function to fail:
///
/// -
/// The hWinEventHook parameter is NULL or not valid.
///
/// -
/// The event hook specified by hWinEventHook was already removed.
///
/// -
/// UnhookWinEvent is called from a thread that is different from the original call to SetWinEventHook.
///
///
///
///
///
/// This function removes the event hook specified by hWinEventHook that prevents the corresponding callback function from receiving
/// further event notifications. If the client's thread ends, the system automatically calls this function.
///
///
/// Call this function from the same thread that installed the event hook. UnhookWinEvent fails if called from a thread
/// different from the call that corresponds to SetWinEventHook.
///
///
/// If WINEVENT_INCONTEXT was specified when this event hook was installed, the system attempts to unload the corresponding DLL from
/// all processes that loaded it. Although unloading does not occur immediately, the hook function is not called after
/// UnhookWinEvent returns. For more information on WINEVENT_INCONTEXT, see In-Context Hook Functions.
///
///
// https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-unhookwinevent BOOL UnhookWinEvent( HWINEVENTHOOK
// hWinEventHook );
[DllImport(Lib.User32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("winuser.h", MSDNShortId = "5cffb279-85e1-4f7a-8bbb-d0d618f6afcd")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool UnhookWinEvent(HWINEVENTHOOK hWinEventHook);
///
/// Contains information passed to a WH_CBT hook procedure, CBTProc, before a window is created.
///
// https://docs.microsoft.com/en-us/windows/desktop/api/winuser/ns-winuser-tagcbt_createwnda typedef struct tagCBT_CREATEWNDA {
// struct tagCREATESTRUCTA *lpcs; HWND hwndInsertAfter; } CBT_CREATEWNDA, *LPCBT_CREATEWNDA;
[PInvokeData("winuser.h", MSDNShortId = "cbt_createwnd.htm")]
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public struct CBT_CREATEWND
{
///
/// Type: LPCREATESTRUCT
/// A pointer to a CREATESTRUCT structure that contains initialization parameters for the window about to be created.
///
public IntPtr lpcs;
///
/// Type: HWND
///
/// A handle to the window whose position in the Z order precedes that of the window being created. This member can also be NULL.
///
///
public HWND hwndInsertAfter;
}
///
/// Contains information passed to a WH_CBT hook procedure, CBTProc, before a window is activated.
///
// https://docs.microsoft.com/en-us/windows/desktop/api/winuser/ns-winuser-tagcbtactivatestruct typedef struct tagCBTACTIVATESTRUCT
// { BOOL fMouse; HWND hWndActive; } CBTACTIVATESTRUCT, *LPCBTACTIVATESTRUCT;
[PInvokeData("winuser.h", MSDNShortId = "cbtactivatestruct.htm")]
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public struct CBTACTIVATESTRUCT
{
///
/// Type: BOOL
/// This member is TRUE if a mouse click is causing the activation or FALSE if it is not.
///
[MarshalAs(UnmanagedType.Bool)]
public bool fMouse;
///
/// Type: HWND
/// A handle to the active window.
///
public HWND hWndActive;
}
///
/// Defines the message parameters passed to a WH_CALLWNDPROCRET hook procedure, CallWndRetProc.
///
// https://docs.microsoft.com/en-us/windows/desktop/api/winuser/ns-winuser-tagcwpretstruct typedef struct tagCWPRETSTRUCT { LRESULT
// lResult; LPARAM lParam; WPARAM wParam; UINT message; HWND hwnd; } CWPRETSTRUCT, *PCWPRETSTRUCT, *NPCWPRETSTRUCT, *LPCWPRETSTRUCT;
[PInvokeData("winuser.h", MSDNShortId = "cwpretstruct.htm")]
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public struct CWPRETSTRUCT
{
///
/// Type: LRESULT
/// The return value of the window procedure that processed the message specified by the message value.
///
public IntPtr lResult;
///
/// Type: LPARAM
/// Additional information about the message. The exact meaning depends on the message value.
///
public IntPtr lParam;
///
/// Type: WPARAM
/// Additional information about the message. The exact meaning depends on the message value.
///
public IntPtr wParam;
///
/// Type: UINT
/// The message.
///
public uint message;
///
/// Type: HWND
/// A handle to the window that processed the message specified by the message value.
///
public HWND hwnd;
}
///
/// Defines the message parameters passed to a WH_CALLWNDPROC hook procedure, CallWndProc.
///
// https://docs.microsoft.com/en-us/windows/desktop/api/winuser/ns-winuser-tagcwpstruct typedef struct tagCWPSTRUCT { LPARAM lParam;
// WPARAM wParam; UINT message; HWND hwnd; } CWPSTRUCT, *PCWPSTRUCT, *NPCWPSTRUCT, *LPCWPSTRUCT;
[PInvokeData("winuser.h", MSDNShortId = "cwpstruct.htm")]
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public struct CWPSTRUCT
{
///
/// Type: LPARAM
/// Additional information about the message. The exact meaning depends on the message value.
///
public IntPtr lParam;
///
/// Type: WPARAM
/// Additional information about the message. The exact meaning depends on the message value.
///
public IntPtr wParam;
///
/// Type: UINT
/// The message.
///
public uint message;
///
/// Type: HWND
/// A handle to the window to receive the message.
///
public HWND hwnd;
}
///
/// Contains debugging information passed to a WH_DEBUG hook procedure, DebugProc.
///
// https://docs.microsoft.com/en-us/windows/desktop/api/winuser/ns-winuser-tagdebughookinfo typedef struct tagDEBUGHOOKINFO { DWORD
// idThread; DWORD idThreadInstaller; LPARAM lParam; WPARAM wParam; int code; } DEBUGHOOKINFO, *PDEBUGHOOKINFO, *NPDEBUGHOOKINFO, *LPDEBUGHOOKINFO;
[PInvokeData("winuser.h", MSDNShortId = "debughookinfo.htm")]
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public struct DEBUGHOOKINFO
{
///
/// Type: DWORD
/// A handle to the thread containing the filter function.
///
public uint idThread;
///
/// Type: DWORD
/// A handle to the thread that installed the debugging filter function.
///
public uint idThreadInstaller;
///
/// Type: LPARAM
/// The value to be passed to the hook in the lParam parameter of the DebugProc callback function.
///
public IntPtr lParam;
///
/// Type: WPARAM
/// The value to be passed to the hook in the wParam parameter of the DebugProc callback function.
///
public IntPtr wParam;
///
/// Type: int
/// The value to be passed to the hook in the nCode parameter of the DebugProc callback function.
///
public int code;
}
///
///
/// Contains information about a hardware message sent to the system message queue. This structure is used to store message
/// information for the JournalPlaybackProc callback function.
///
///
// https://docs.microsoft.com/en-us/windows/desktop/api/winuser/ns-winuser-tageventmsg typedef struct tagEVENTMSG { UINT message;
// UINT paramL; UINT paramH; DWORD time; HWND hwnd; } EVENTMSG, *PEVENTMSGMSG, *NPEVENTMSGMSG, *LPEVENTMSGMSG, *PEVENTMSG,
// *NPEVENTMSG, *LPEVENTMSG;
[PInvokeData("winuser.h", MSDNShortId = "eventmsg.htm")]
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public struct EVENTMSG
{
///
/// Type: UINT
/// The message.
///
public uint message;
///
/// Type: UINT
/// Additional information about the message. The exact meaning depends on the message value.
///
public uint paramL;
///
/// Type: UINT
/// Additional information about the message. The exact meaning depends on the message value.
///
public uint paramH;
///
/// Type: DWORD
/// The time at which the message was posted.
///
public uint time;
///
/// Type: HWND
/// A handle to the window to which the message was posted.
///
public HWND hwnd;
}
/// Provides a handle to a hook.
[StructLayout(LayoutKind.Sequential)]
public struct HHOOK : IUserHandle
{
private IntPtr handle;
/// Initializes a new instance of the struct.
/// An object that represents the pre-existing handle to use.
public HHOOK(IntPtr preexistingHandle) => handle = preexistingHandle;
/// Returns an invalid handle by instantiating a object with .
public static HHOOK NULL => new HHOOK(IntPtr.Zero);
/// Gets a value indicating whether this instance is a null handle.
public bool IsNull => handle == IntPtr.Zero;
/// Performs an explicit conversion from to .
/// The handle.
/// The result of the conversion.
public static explicit operator IntPtr(HHOOK h) => h.handle;
/// Performs an implicit conversion from to .
/// The pointer to a handle.
/// The result of the conversion.
public static implicit operator HHOOK(IntPtr h) => new HHOOK(h);
/// Implements the operator !=.
/// The first handle.
/// The second handle.
/// The result of the operator.
public static bool operator !=(HHOOK h1, HHOOK h2) => !(h1 == h2);
/// Implements the operator ==.
/// The first handle.
/// The second handle.
/// The result of the operator.
public static bool operator ==(HHOOK h1, HHOOK h2) => h1.Equals(h2);
///
public override bool Equals(object obj) => obj is HHOOK h ? handle == h.handle : false;
///
public override int GetHashCode() => handle.GetHashCode();
///
public IntPtr DangerousGetHandle() => handle;
}
/// Provides a handle to a Windows Event Hook.
[StructLayout(LayoutKind.Sequential)]
public struct HWINEVENTHOOK : IHandle
{
private IntPtr handle;
/// Initializes a new instance of the struct.
/// An object that represents the pre-existing handle to use.
public HWINEVENTHOOK(IntPtr preexistingHandle) => handle = preexistingHandle;
/// Returns an invalid handle by instantiating a object with .
public static HWINEVENTHOOK NULL => new HWINEVENTHOOK(IntPtr.Zero);
/// Gets a value indicating whether this instance is a null handle.
public bool IsNull => handle == IntPtr.Zero;
/// Performs an explicit conversion from to .
/// The handle.
/// The result of the conversion.
public static explicit operator IntPtr(HWINEVENTHOOK h) => h.handle;
/// Performs an implicit conversion from to .
/// The pointer to a handle.
/// The result of the conversion.
public static implicit operator HWINEVENTHOOK(IntPtr h) => new HWINEVENTHOOK(h);
/// Implements the operator !=.
/// The first handle.
/// The second handle.
/// The result of the operator.
public static bool operator !=(HWINEVENTHOOK h1, HWINEVENTHOOK h2) => !(h1 == h2);
/// Implements the operator ==.
/// The first handle.
/// The second handle.
/// The result of the operator.
public static bool operator ==(HWINEVENTHOOK h1, HWINEVENTHOOK h2) => h1.Equals(h2);
///
public override bool Equals(object obj) => obj is HWINEVENTHOOK h ? handle == h.handle : false;
///
public override int GetHashCode() => handle.GetHashCode();
///
public IntPtr DangerousGetHandle() => handle;
}
///
/// Contains information about a low-level keyboard input event.
///
// https://docs.microsoft.com/en-us/windows/desktop/api/winuser/ns-winuser-tagkbdllhookstruct typedef struct tagKBDLLHOOKSTRUCT {
// DWORD vkCode; DWORD scanCode; DWORD flags; DWORD time; ULONG_PTR dwExtraInfo; } KBDLLHOOKSTRUCT, *LPKBDLLHOOKSTRUCT, *PKBDLLHOOKSTRUCT;
[PInvokeData("winuser.h", MSDNShortId = "kbdllhookstruct.htm")]
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public struct KBDLLHOOKSTRUCT
{
///
/// Type: DWORD
/// A virtual-key code. The code must be a value in the range 1 to 254.
///
public uint vkCode;
///
/// Type: DWORD
/// A hardware scan code for the key.
///
public uint scanCode;
///
/// Type: DWORD
///
/// The extended-key flag, event-injected flags, context code, and transition-state flag. This member is specified as follows.
/// An application can use the following values to test the keystroke flags. Testing LLKHF_INJECTED (bit 4) will tell you
/// whether the event was injected. If it was, then testing LLKHF_LOWER_IL_INJECTED (bit 1) will tell you whether or not the
/// event was injected from a process running at lower integrity level.
///
///
///
/// Value
/// Meaning
///
/// -
/// LLKHF_EXTENDED (KF_EXTENDED >> 8)
/// Test the extended-key flag.
///
/// -
/// LLKHF_LOWER_IL_INJECTED 0x00000002
/// Test the event-injected (from a process running at lower integrity level) flag.
///
/// -
/// LLKHF_INJECTED 0x00000010
/// Test the event-injected (from any process) flag.
///
/// -
/// LLKHF_ALTDOWN (KF_ALTDOWN >> 8)
/// Test the context code.
///
/// -
/// LLKHF_UP (KF_UP >> 8)
/// Test the transition-state flag.
///
///
/// The following table describes the layout of this value.
///
///
/// Bits
/// Description
///
/// -
/// 0
///
/// Specifies whether the key is an extended key, such as a function key or a key on the numeric keypad. The value is 1 if the
/// key is an extended key; otherwise, it is 0.
///
///
/// -
/// 1
///
/// Specifies whether the event was injected from a process running at lower integrity level. The value is 1 if that is the
/// case; otherwise, it is 0. Note that bit 4 is also set whenever bit 1 is set.
///
///
/// -
/// 2-3
/// Reserved.
///
/// -
/// 4
///
/// Specifies whether the event was injected. The value is 1 if that is the case; otherwise, it is 0. Note that bit 1 is not
/// necessarily set when bit 4 is set.
///
///
/// -
/// 5
/// The context code. The value is 1 if the ALT key is pressed; otherwise, it is 0.
///
/// -
/// 6
/// Reserved.
///
/// -
/// 7
/// The transition state. The value is 0 if the key is pressed and 1 if it is being released.
///
///
///
public uint flags;
///
/// Type: DWORD
/// The time stamp for this message, equivalent to what GetMessageTime would return for this message.
///
public uint time;
///
/// Type: ULONG_PTR
/// Additional information associated with the message.
///
public UIntPtr dwExtraInfo;
}
///
/// Contains information about a mouse event passed to a WH_MOUSE hook procedure, MouseProc.
///
// https://docs.microsoft.com/en-us/windows/desktop/api/winuser/ns-winuser-tagmousehookstruct typedef struct tagMOUSEHOOKSTRUCT {
// POINT pt; HWND hwnd; UINT wHitTestCode; ULONG_PTR dwExtraInfo; } MOUSEHOOKSTRUCT, *LPMOUSEHOOKSTRUCT, *PMOUSEHOOKSTRUCT;
[PInvokeData("winuser.h", MSDNShortId = "mousehookstruct.htm")]
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public struct MOUSEHOOKSTRUCT
{
///
/// Type: POINT
/// The x- and y-coordinates of the cursor, in screen coordinates.
///
public System.Drawing.Point pt;
///
/// Type: HWND
/// A handle to the window that will receive the mouse message corresponding to the mouse event.
///
public HWND hwnd;
///
/// Type: UINT
/// The hit-test value. For a list of hit-test values, see the description of the WM_NCHITTEST message.
///
public uint wHitTestCode;
///
/// Type: ULONG_PTR
/// Additional information associated with the message.
///
public UIntPtr dwExtraInfo;
}
///
/// Contains information about a mouse event passed to a WH_MOUSE hook procedure, MouseProc.
///
/// This is an extension of the MOUSEHOOKSTRUCT structure that includes information about wheel movement or the use of the X button.
///
///
// https://docs.microsoft.com/en-us/windows/desktop/api/winuser/ns-winuser-tagmousehookstructex typedef struct tagMOUSEHOOKSTRUCTEX
// { DWORD mouseData; base_class tagMOUSEHOOKSTRUCT; } MOUSEHOOKSTRUCTEX, *LPMOUSEHOOKSTRUCTEX, *PMOUSEHOOKSTRUCTEX;
[PInvokeData("winuser.h", MSDNShortId = "mousehookstructex.htm")]
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public struct MOUSEHOOKSTRUCTEX
{
///
/// Type: POINT
/// The x- and y-coordinates of the cursor, in screen coordinates.
///
public System.Drawing.Point pt;
///
/// Type: HWND
/// A handle to the window that will receive the mouse message corresponding to the mouse event.
///
public HWND hwnd;
///
/// Type: UINT
/// The hit-test value. For a list of hit-test values, see the description of the WM_NCHITTEST message.
///
public uint wHitTestCode;
///
/// Type: ULONG_PTR
/// Additional information associated with the message.
///
public UIntPtr dwExtraInfo;
///
/// Type: DWORD
///
/// If the message is WM_MOUSEWHEEL, the HIWORD of this member is the wheel delta. The LOWORD is undefined and reserved. A
/// positive value indicates that the wheel was rotated forward, away from the user; a negative value indicates that the wheel
/// was rotated backward, toward the user. One wheel click is defined as WHEEL_DELTA, which is 120.
///
///
/// If the message is WM_XBUTTONDOWN, WM_XBUTTONUP, WM_XBUTTONDBLCLK, WM_NCXBUTTONDOWN, WM_NCXBUTTONUP, or WM_NCXBUTTONDBLCLK,
/// the HIWORD of mouseData specifies which X button was pressed or released, and the LOWORD is undefined and reserved.
/// This member can be one or more of the following values. Otherwise, mouseData is not used.
///
///
///
/// Value
/// Meaning
///
/// -
/// XBUTTON1 0x0001
/// The first X button was pressed or released.
///
/// -
/// XBUTTON2 0x0002
/// The second X button was pressed or released.
///
///
///
public uint mouseData;
}
///
/// Contains information about a low-level mouse input event.
///
// https://docs.microsoft.com/en-us/windows/desktop/api/winuser/ns-winuser-tagmsllhookstruct typedef struct tagMSLLHOOKSTRUCT {
// POINT pt; DWORD mouseData; DWORD flags; DWORD time; ULONG_PTR dwExtraInfo; } MSLLHOOKSTRUCT, *LPMSLLHOOKSTRUCT, *PMSLLHOOKSTRUCT;
[PInvokeData("winuser.h", MSDNShortId = "msllhookstruct.htm")]
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public struct MSLLHOOKSTRUCT
{
///
/// Type: POINT
/// The x- and y-coordinates of the cursor, in per-monitor-aware screen coordinates.
///
public System.Drawing.Point pt;
///
/// Type: DWORD
///
/// If the message is WM_MOUSEWHEEL, the high-order word of this member is the wheel delta. The low-order word is reserved. A
/// positive value indicates that the wheel was rotated forward, away from the user; a negative value indicates that the wheel
/// was rotated backward, toward the user. One wheel click is defined as WHEEL_DELTA, which is 120.
///
///
/// If the message is WM_XBUTTONDOWN, WM_XBUTTONUP, WM_XBUTTONDBLCLK, WM_NCXBUTTONDOWN, WM_NCXBUTTONUP, or WM_NCXBUTTONDBLCLK,
/// the high-order word specifies which X button was pressed or released, and the low-order word is reserved. This value can be
/// one or more of the following values. Otherwise, mouseData is not used.
///
///
///
/// Value
/// Meaning
///
/// -
/// XBUTTON1 0x0001
/// The first X button was pressed or released.
///
/// -
/// XBUTTON2 0x0002
/// The second X button was pressed or released.
///
///
///
public uint mouseData;
///
/// Type: DWORD
///
/// The event-injected flags. An application can use the following values to test the flags. Testing LLMHF_INJECTED (bit 0) will
/// tell you whether the event was injected. If it was, then testing LLMHF_LOWER_IL_INJECTED (bit 1) will tell you whether or
/// not the event was injected from a process running at lower integrity level.
///
///
///
/// Value
/// Meaning
///
/// -
/// LLMHF_INJECTED 0x00000001
/// Test the event-injected (from any process) flag.
///
/// -
/// LLMHF_LOWER_IL_INJECTED 0x00000002
/// Test the event-injected (from a process running at lower integrity level) flag.
///
///
///
public uint flags;
///
/// Type: DWORD
/// The time stamp for this message.
///
public uint time;
///
/// Type: ULONG_PTR
/// Additional information associated with the message.
///
public UIntPtr dwExtraInfo;
}
///
///
/// This topic describes the events that are generated by the operating system and by server applications. The constants are listed
/// in alphabetical order.
///
///
/// Prior to using these events, client applications should use Accessible Event Watcher to verify that these events are used by UI elements.
///
///
/// For more information about events in general, see What Are WinEvents? and System Level and Object Level Events. For more
/// information about the events sent by the system, see Appendix A: Supported User Interface Elements Reference.
///
///
// https://docs.microsoft.com/en-us/windows/win32/winauto/event-constants
[PInvokeData("", MSDNShortId = "e27b135d-4faf-401e-a6c1-64ed0e1b5de5")]
public static class EventConstants
{
///
/// The range of WinEvent constant values specified by the Accessibility Interoperability Alliance (AIA) for use across the
/// industry. For more information, see Allocation of WinEvent IDs.
///
public const uint EVENT_AIA_END = 0xAFFF;
///
/// The range of WinEvent constant values specified by the Accessibility Interoperability Alliance (AIA) for use across the
/// industry. For more information, see Allocation of WinEvent IDs.
///
public const uint EVENT_AIA_START = 0xA000;
///
public const uint EVENT_CONSOLE_CARET = 0x4001;
///
public const uint EVENT_CONSOLE_END = 0x40FF;
///
public const uint EVENT_CONSOLE_END_APPLICATION = 0x4007;
///
public const uint EVENT_CONSOLE_LAYOUT = 0x4005;
///
public const uint EVENT_CONSOLE_START_APPLICATION = 0x4006;
///
public const uint EVENT_CONSOLE_UPDATE_REGION = 0x4002;
///
public const uint EVENT_CONSOLE_UPDATE_SCROLL = 0x4004;
///
public const uint EVENT_CONSOLE_UPDATE_SIMPLE = 0x4003;
/// The highest possible event values.
public const uint EVENT_MAX = 0x7FFFFFFF;
/// The lowest possible event values.
public const uint EVENT_MIN = 0x00000001;
///
/// An object's KeyboardShortcut property has changed. Server applications send this event for their accessible objects.
///
public const uint EVENT_OBJECT_ACCELERATORCHANGE = 0x8012;
/// Sent when a window is cloaked. A cloaked window still exists, but is invisible to the user.
public const uint EVENT_OBJECT_CLOAKED = 0x8017;
///
/// A window object's scrolling has ended. Unlike EVENT_SYSTEM_SCROLLEND, this event is associated with the scrolling window.
/// Whether the scrolling is horizontal or vertical scrolling, this event should be sent whenever the scroll action is completed.
///
/// The hwnd parameter of the WinEventProc callback function describes the scrolling window; the idObject parameter is
/// OBJID_CLIENT, and the idChild parameter is CHILDID_SELF.
///
///
public const uint EVENT_OBJECT_CONTENTSCROLLED = 0x8015;
///
/// An object has been created. The system sends this event for the following user interface elements: caret, header control,
/// list-view control, tab control, toolbar control, tree view control, and window object. Server applications send this event
/// for their accessible objects.
///
/// Before sending the event for the parent object, servers must send it for all of an object's child objects. Servers must
/// ensure that all child objects are fully created and ready to accept IAccessible calls from clients before the parent object
/// sends this event.
///
///
/// Because a parent object is created after its child objects, clients must make sure that an object's parent has been created
/// before calling IAccessible::get_accParent, particularly if in-context hook functions are used.
///
///
public const uint EVENT_OBJECT_CREATE = 0x8000;
///
/// An object's DefaultAction property has changed. The system sends this event for dialog boxes. Server applications send this
/// event for their accessible objects.
///
public const uint EVENT_OBJECT_DEFACTIONCHANGE = 0x8011;
/// An object's Description property has changed. Server applications send this event for their accessible objects.
public const uint EVENT_OBJECT_DESCRIPTIONCHANGE = 0x800D;
///
/// An object has been destroyed. The system sends this event for the following user interface elements: caret, header control,
/// list-view control, tab control, toolbar control, tree view control, and window object. Server applications send this event
/// for their accessible objects.
/// Clients assume that all of an object's children are destroyed when the parent object sends this event.
///
/// After receiving this event, clients do not call an object's IAccessible properties or methods. However, the interface
/// pointer must remain valid as long as there is a reference count on it (due to COM rules), but the UI element may no longer
/// be present. Further calls on the interface pointer may return failure errors; to prevent this, servers create proxy objects
/// and monitor their life spans.
///
///
public const uint EVENT_OBJECT_DESTROY = 0x8001;
///
/// The user has ended a drag operation before dropping the dragged element on a drop target. The hwnd, idObject, and idChild
/// parameters of the WinEventProc callback function identify the object being dragged.
///
public const uint EVENT_OBJECT_DRAGCANCEL = 0x8022;
///
/// The user dropped an element on a drop target. The hwnd, idObject, and idChild parameters of the WinEventProc callback
/// function identify the object being dragged.
///
public const uint EVENT_OBJECT_DRAGCOMPLETE = 0x8023;
///
/// The user dropped an element on a drop target. The hwnd, idObject, and idChild parameters of the WinEventProc callback
/// function identify the drop target.
///
public const uint EVENT_OBJECT_DRAGDROPPED = 0x8026;
///
/// The user dragged an element into a drop target's boundary. The hwnd, idObject, and idChild parameters of the WinEventProc
/// callback function identify the drop target.
///
public const uint EVENT_OBJECT_DRAGENTER = 0x8024;
///
/// The user dragged an element out of a drop target's boundary. The hwnd, idObject, and idChild parameters of the WinEventProc
/// callback function identify the drop target.
///
public const uint EVENT_OBJECT_DRAGLEAVE = 0x8025;
///
/// The user started to drag an element. The hwnd, idObject, and idChild parameters of the WinEventProc callback function
/// identify the object being dragged.
///
public const uint EVENT_OBJECT_DRAGSTART = 0x8021;
/// The highest object event value.
public const uint EVENT_OBJECT_END = 0x80FF;
///
/// An object has received the keyboard focus. The system sends this event for the following user interface elements: list-view
/// control, menu bar, pop-up menu, switch window, tab control, tree view control, and window object. Server applications send
/// this event for their accessible objects.
/// The hwnd parameter of the WinEventProc callback function identifies the window that receives the keyboard focus.
///
public const uint EVENT_OBJECT_FOCUS = 0x8005;
/// An object's Help property has changed. Server applications send this event for their accessible objects.
public const uint EVENT_OBJECT_HELPCHANGE = 0x8010;
///
/// An object is hidden. The system sends this event for the following user interface elements: caret and cursor. Server
/// applications send this event for their accessible objects.
///
/// When this event is generated for a parent object, all child objects are already hidden. Server applications do not send this
/// event for the child objects.
///
///
/// Hidden objects include the STATE_SYSTEM_INVISIBLE flag; shown objects do not include this flag. The EVENT_OBJECT_HIDE event
/// also indicates that the STATE_SYSTEM_INVISIBLE flag is set. Therefore, servers do not send the EVENT_STATE_CHANGE event in
/// this case.
///
///
public const uint EVENT_OBJECT_HIDE = 0x8003;
///
/// A window that hosts other accessible objects has changed the hosted objects. A client might need to query the host window to
/// discover the new hosted objects, especially if the client has been monitoring events from the window. A hosted object is an
/// object from an accessibility framework (MSAA or UI Automation) that is different from that of the host. Changes in hosted
/// objects that are from the same framework as the host should be handed with the structural change events, such as
/// EVENT_OBJECT_CREATE for MSAA. For more info see comments within winuser.h.
///
public const uint EVENT_OBJECT_HOSTEDOBJECTSINVALIDATED = 0x8020;
/// The size or position of an IME window has changed.
public const uint EVENT_OBJECT_IME_CHANGE = 0x8029;
/// An IME window has become hidden.
public const uint EVENT_OBJECT_IME_HIDE = 0x8028;
/// An IME window has become visible.
public const uint EVENT_OBJECT_IME_SHOW = 0x8027;
///
/// An object has been invoked; for example, the user has clicked a button. This event is supported by common controls and is
/// used by UI Automation.
///
/// For this event, the hwnd, ID, and idChild parameters of the WinEventProc callback function identify the item that is invoked.
///
///
public const uint EVENT_OBJECT_INVOKED = 0x8013;
///
/// An object that is part of a live region has changed. A live region is an area of an application that changes frequently
/// and/or asynchronously.
///
public const uint EVENT_OBJECT_LIVEREGIONCHANGED = 0x8019;
///
/// An object has changed location, shape, or size. The system sends this event for the following user interface elements: caret
/// and window objects. Server applications send this event for their accessible objects.
///
/// This event is generated in response to a change in the top-level object within the object hierarchy; it is not generated for
/// any children that the object might have. For example, if the user resizes a window, the system sends this notification for
/// the window, but not for the menu bar, title bar, scroll bar, or other objects that have also changed.
///
///
/// The system does not send this event for every non-floating child window when the parent moves. However, if an application
/// explicitly resizes child windows as a result of resizing the parent window, the system sends multiple events for the resized children.
///
///
/// If an object's State property is set to STATE_SYSTEM_FLOATING, the server sends EVENT_OBJECT_LOCATIONCHANGE whenever the
/// object changes location. If an object does not have this state, servers only trigger this event when the object moves in
/// relation to its parent. For this event notification, the idChild parameter of the WinEventProc callback function identifies
/// the child object that has changed.
///
///
public const uint EVENT_OBJECT_LOCATIONCHANGE = 0x800B;
///
/// An object's Name property has changed. The system sends this event for the following user interface elements: check box,
/// cursor, list-view control, push button, radio button, status bar control, tree view control, and window object. Server
/// applications send this event for their accessible objects.
///
public const uint EVENT_OBJECT_NAMECHANGE = 0x800C;
/// An object has a new parent object. Server applications send this event for their accessible objects.
public const uint EVENT_OBJECT_PARENTCHANGE = 0x800F;
///
/// A container object has added, removed, or reordered its children. The system sends this event for the following user
/// interface elements: header control, list-view control, toolbar control, and window object. Server applications send this
/// event as appropriate for their accessible objects.
///
/// For example, this event is generated by a list-view object when the number of child elements or the order of the elements
/// changes. This event is also sent by a parent window when the Z-order for the child windows changes.
///
///
public const uint EVENT_OBJECT_REORDER = 0x8004;
///
/// The selection within a container object has changed. The system sends this event for the following user interface elements:
/// list-view control, tab control, tree view control, and window object. Server applications send this event for their
/// accessible objects.
///
/// This event signals a single selection: either a child is selected in a container that previously did not contain any
/// selected children, or the selection has changed from one child to another.
///
///
/// The hwnd and idObject parameters of the WinEventProc callback function describe the container; the idChild parameter
/// identifies the object that is selected. If the selected child is a window that also contains objects, the idChild parameter
/// is OBJID_WINDOW.
///
///
public const uint EVENT_OBJECT_SELECTION = 0x8006;
///
/// A child within a container object has been added to an existing selection. The system sends this event for the following
/// user interface elements: list box, list-view control, and tree view control. Server applications send this event for their
/// accessible objects.
///
/// The hwnd and idObject parameters of the WinEventProc callback function describe the container. The idChild parameter is the
/// child that is added to the selection.
///
///
public const uint EVENT_OBJECT_SELECTIONADD = 0x8007;
///
/// An item within a container object has been removed from the selection. The system sends this event for the following user
/// interface elements: list box, list-view control, and tree view control. Server applications send this event for their
/// accessible objects.
/// This event signals that a child is removed from an existing selection.
///
/// The hwnd and idObject parameters of the WinEventProc callback function describe the container; the idChild parameter
/// identifies the child that has been removed from the selection.
///
///
public const uint EVENT_OBJECT_SELECTIONREMOVE = 0x8008;
///
/// Numerous selection changes have occurred within a container object. The system sends this event for list boxes; server
/// applications send it for their accessible objects.
///
/// This event is sent when the selected items within a control have changed substantially. The event informs the client that
/// many selection changes have occurred, and it is sent instead of several EVENT_OBJECT_SELECTIONADD or
/// EVENT_OBJECT_SELECTIONREMOVE events. The client queries for the selected items by calling the container object's
/// IAccessible::get_accSelection method and enumerating the selected items.
///
///
/// For this event notification, the hwnd and idObject parameters of the WinEventProc callback function describe the container
/// in which the changes occurred.
///
///
public const uint EVENT_OBJECT_SELECTIONWITHIN = 0x8009;
///
/// A hidden object is shown. The system sends this event for the following user interface elements: caret, cursor, and window
/// object. Server applications send this event for their accessible objects.
///
/// Clients assume that when this event is sent by a parent object, all child objects are already displayed. Therefore, server
/// applications do not send this event for the child objects.
///
///
/// Hidden objects include the STATE_SYSTEM_INVISIBLE flag; shown objects do not include this flag. The EVENT_OBJECT_SHOW event
/// also indicates that the STATE_SYSTEM_INVISIBLE flag is cleared. Therefore, servers do not send the EVENT_STATE_CHANGE event
/// in this case.
///
///
public const uint EVENT_OBJECT_SHOW = 0x8002;
///
/// An object's state has changed. The system sends this event for the following user interface elements: check box, combo box,
/// header control, push button, radio button, scroll bar, toolbar control, tree view control, up-down control, and window
/// object. Server applications send this event for their accessible objects.
/// For example, a state change occurs when a button object is clicked or released, or when an object is enabled or disabled.
///
/// For this event notification, the idChild parameter of the WinEventProc callback function identifies the child object whose
/// state has changed.
///
///
public const uint EVENT_OBJECT_STATECHANGE = 0x800A;
///
/// The conversion target within an IME composition has changed. The conversion target is the subset of the IME composition
/// which is actively selected as the target for user-initiated conversions.
///
public const uint EVENT_OBJECT_TEXTEDIT_CONVERSIONTARGETCHANGED = 0x8030;
///
/// An object's text selection has changed. This event is supported by common controls and is used by UI Automation.
///
/// The hwnd, ID, and idChild parameters of the WinEventProc callback function describe the item that is contained in the
/// updated text selection.
///
///
public const uint EVENT_OBJECT_TEXTSELECTIONCHANGED = 0x8014;
/// Sent when a window is uncloaked. A cloaked window still exists, but is invisible to the user.
public const uint EVENT_OBJECT_UNCLOAKED = 0x8018;
///
/// An object's Value property has changed. The system sends this event for the user interface elements that include the scroll
/// bar and the following controls: edit, header, hot key, progress bar, slider, and up-down. Server applications send this
/// event for their accessible objects.
///
public const uint EVENT_OBJECT_VALUECHANGE = 0x800E;
/// The range of event constant values reserved for OEMs. For more information, see Allocation of WinEvent IDs.
public const uint EVENT_OEM_DEFINED_END = 0x01FF;
/// The range of event constant values reserved for OEMs. For more information, see Allocation of WinEvent IDs.
public const uint EVENT_OEM_DEFINED_START = 0x0101;
/// An alert has been generated. Server applications should not send this event.
public const uint EVENT_SYSTEM_ALERT = 0x0002;
/// A preview rectangle is being displayed.
public const uint EVENT_SYSTEM_ARRANGMENTPREVIEW = 0x8016;
/// A window has lost mouse capture. This event is sent by the system, never by servers.
public const uint EVENT_SYSTEM_CAPTUREEND = 0x0009;
/// A window has received mouse capture. This event is sent by the system, never by servers.
public const uint EVENT_SYSTEM_CAPTURESTART = 0x0008;
/// A window has exited context-sensitive Help mode. This event is not sent consistently by the system.
public const uint EVENT_SYSTEM_CONTEXTHELPEND = 0x000D;
/// A window has entered context-sensitive Help mode. This event is not sent consistently by the system.
public const uint EVENT_SYSTEM_CONTEXTHELPSTART = 0x000C;
/// The active desktop has been switched.
public const uint EVENT_SYSTEM_DESKTOPSWITCH = 0x0020;
///
/// A dialog box has been closed. The system sends this event for standard dialog boxes; servers send it for custom dialog
/// boxes. This event is not sent consistently by the system.
///
public const uint EVENT_SYSTEM_DIALOGEND = 0x0011;
///
/// A dialog box has been displayed. The system sends this event for standard dialog boxes, which are created using resource
/// templates or Win32 dialog box functions. Servers send this event for custom dialog boxes, which are windows that function as
/// dialog boxes but are not created in the standard way.
/// This event is not sent consistently by the system.
///
public const uint EVENT_SYSTEM_DIALOGSTART = 0x0010;
///
/// An application is about to exit drag-and-drop mode. Applications that support drag-and-drop operations must send this event;
/// the system does not send this event.
///
public const uint EVENT_SYSTEM_DRAGDROPEND = 0x000F;
///
/// An application is about to enter drag-and-drop mode. Applications that support drag-and-drop operations must send this event
/// because the system does not send it.
///
public const uint EVENT_SYSTEM_DRAGDROPSTART = 0x000E;
/// The highest system event value.
public const uint EVENT_SYSTEM_END = 0x00FF;
///
/// The foreground window has changed. The system sends this event even if the foreground window has changed to another window
/// in the same thread. Server applications never send this event.
///
/// For this event, the WinEventProc callback function's hwnd parameter is the handle to the window that is in the foreground,
/// the idObject parameter is OBJID_WINDOW, and the idChild parameter is CHILDID_SELF.
///
///
public const uint EVENT_SYSTEM_FOREGROUND = 0x0003;
///
public const uint EVENT_SYSTEM_IME_KEY_NOTIFICATION = 0x0029;
///
/// A menu from the menu bar has been closed. The system sends this event for standard menus; servers send it for custom menus.
///
/// For this event, the WinEventProc callback function's hwnd, idObject, and idChild parameters refer to the control that
/// contains the menu bar or the control that activates the context menu. The hwnd parameter is the handle to the window that is
/// related to the event. The idObject parameter is OBJID_MENU or OBJID_SYSMENU for a menu, or OBJID_WINDOW for a pop-up menu.
/// The idChild parameter is CHILDID_SELF.
///
///
public const uint EVENT_SYSTEM_MENUEND = 0x0005;
///
/// A pop-up menu has been closed. The system sends this event for standard menus; servers send it for custom menus.
/// When a pop-up menu is closed, the client receives this message, and then the EVENT_SYSTEM_MENUEND event.
/// This event is not sent consistently by the system.
///
public const uint EVENT_SYSTEM_MENUPOPUPEND = 0x0007;
///
/// A pop-up menu has been displayed. The system sends this event for standard menus, which are identified by HMENU, and are
/// created using menu-template resources or Win32 menu functions. Servers send this event for custom menus, which are user
/// interface elements that function as menus but are not created in the standard way. This event is not sent consistently by
/// the system.
///
public const uint EVENT_SYSTEM_MENUPOPUPSTART = 0x0006;
///
/// A menu item on the menu bar has been selected. The system sends this event for standard menus, which are identified by
/// HMENU, created using menu-template resources or Win32 menu API elements. Servers send this event for custom menus, which are
/// user interface elements that function as menus but are not created in the standard way.
///
/// For this event, the WinEventProc callback function's hwnd, idObject, and idChild parameters refer to the control that
/// contains the menu bar or the control that activates the context menu. The hwnd parameter is the handle to the window related
/// to the event. The idObject parameter is OBJID_MENU or OBJID_SYSMENU for a menu, or OBJID_WINDOW for a pop-up menu. The
/// idChild parameter is CHILDID_SELF.
///
///
/// The system triggers more than one EVENT_SYSTEM_MENUSTART event that does not always correspond with the EVENT_SYSTEM_MENUEND event.
///
///
public const uint EVENT_SYSTEM_MENUSTART = 0x0004;
/// A window object is about to be restored. This event is sent by the system, never by servers.
public const uint EVENT_SYSTEM_MINIMIZEEND = 0x0017;
/// A window object is about to be minimized. This event is sent by the system, never by servers.
public const uint EVENT_SYSTEM_MINIMIZESTART = 0x0016;
/// The movement or resizing of a window has finished. This event is sent by the system, never by servers.
public const uint EVENT_SYSTEM_MOVESIZEEND = 0x000B;
/// A window is being moved or resized. This event is sent by the system, never by servers.
public const uint EVENT_SYSTEM_MOVESIZESTART = 0x000A;
///
/// Scrolling has ended on a scroll bar. This event is sent by the system for standard scroll bar controls and for scroll bars
/// that are attached to a window. Servers send this event for custom scroll bars, which are user interface elements that
/// function as scroll bars but are not created in the standard way.
///
/// The idObject parameter that is sent to the WinEventProc callback function is OBJID_HSCROLL for horizontal scroll bars, and
/// OBJID_VSCROLL for vertical scroll bars.
///
///
public const uint EVENT_SYSTEM_SCROLLINGEND = 0x0013;
///
/// Scrolling has started on a scroll bar. The system sends this event for standard scroll bar controls and for scroll bars
/// attached to a window. Servers send this event for custom scroll bars, which are user interface elements that function as
/// scroll bars but are not created in the standard way.
///
/// The idObject parameter that is sent to the WinEventProc callback function is OBJID_HSCROLL for horizontal scrolls bars, and
/// OBJID_VSCROLL for vertical scroll bars.
///
///
public const uint EVENT_SYSTEM_SCROLLINGSTART = 0x0012;
///
/// A sound has been played. The system sends this event when a system sound, such as one for a menu, is played even if no sound
/// is audible (for example, due to the lack of a sound file or a sound card). Servers send this event whenever a custom UI
/// element generates a sound.
/// For this event, the WinEventProc callback function receives the OBJID_SOUND value as the idObject parameter.
///
public const uint EVENT_SYSTEM_SOUND = 0x0001;
///
/// The user has released ALT+TAB. This event is sent by the system, never by servers. The hwnd parameter of the WinEventProc
/// callback function identifies the window to which the user has switched.
///
/// If only one application is running when the user presses ALT+TAB, the system sends this event without a corresponding
/// EVENT_SYSTEM_SWITCHSTART event.
///
///
public const uint EVENT_SYSTEM_SWITCHEND = 0x0015;
///
public const uint EVENT_SYSTEM_SWITCHER_APPDROPPED = 0x0026;
///
public const uint EVENT_SYSTEM_SWITCHER_APPGRABBED = 0x0024;
///
public const uint EVENT_SYSTEM_SWITCHER_APPOVERTARGET = 0x0025;
///
public const uint EVENT_SYSTEM_SWITCHER_CANCELLED = 0x0027;
///
/// The user has pressed ALT+TAB, which activates the switch window. This event is sent by the system, never by servers. The
/// hwnd parameter of the WinEventProc callback function identifies the window to which the user is switching.
///
/// If only one application is running when the user presses ALT+TAB, the system sends an EVENT_SYSTEM_SWITCHEND event without a
/// corresponding EVENT_SYSTEM_SWITCHSTART event.
///
///
public const uint EVENT_SYSTEM_SWITCHSTART = 0x0014;
///
/// The range of event constant values reserved for UI Automation event identifiers. For more information, see Allocation of
/// WinEvent IDs.
///
public const uint EVENT_UIA_EVENTID_END = 0x4EFF;
///
/// The range of event constant values reserved for UI Automation event identifiers. For more information, see Allocation of
/// WinEvent IDs.
///
public const uint EVENT_UIA_EVENTID_START = 0x4E00;
///
/// The range of event constant values reserved for UI Automation property-changed event identifiers. For more information, see
/// Allocation of WinEvent IDs.
///
public const uint EVENT_UIA_PROPID_END = 0x75FF;
///
/// The range of event constant values reserved for UI Automation property-changed event identifiers. For more information, see
/// Allocation of WinEvent IDs.
///
public const uint EVENT_UIA_PROPID_START = 0x7500;
}
///
///
/// This topic describes the Microsoft Active Accessibility object identifiers, 32-bit values that identify categories of accessible
/// objects within a window. Microsoft Active Accessibility servers and Microsoft UI Automation providers use the object identifiers
/// to determine the object to which a WM_GETOBJECT message request refers.
///
///
/// Clients receive these values in their WinEventProc callback function and use them to identify parts of a window. Servers use
/// these values to identify the corresponding parts of a window when calling NotifyWinEvent or when responding to the
/// WM_GETOBJECT message.
///
///
/// Servers can define custom object IDs to identify other categories of objects within their applications. Custom object IDs must
/// be assigned positive values because Microsoft Active Accessibility reserves zero and all negative values for the following
/// standard object identifiers.
///
///
// https://docs.microsoft.com/en-us/windows/win32/winauto/object-identifiers
[PInvokeData("winuser.h", MSDNShortId = "dc1603f8-29e5-4acd-817a-c6957feaff6c")]
public static class ObjectIdentifiers
{
/// The window itself rather than a child object.
public const int OBJID_WINDOW = unchecked((int)0x00000000);
/// The window's system menu.
public const int OBJID_SYSMENU = unchecked((int)0xFFFFFFFF);
/// The window's title bar.
public const int OBJID_TITLEBAR = unchecked((int)0xFFFFFFFE);
/// The window's menu bar.
public const int OBJID_MENU = unchecked((int)0xFFFFFFFD);
///
/// The window's client area. In most cases, the operating system controls the frame elements and the client object contains all
/// elements that are controlled by the application. Servers only process the WM_GETOBJECT messages in which the lParam is
/// OBJID_CLIENT, OBJID_WINDOW, or a custom object identifier.
///
public const int OBJID_CLIENT = unchecked((int)0xFFFFFFFC);
/// The window's vertical scroll bar.
public const int OBJID_VSCROLL = unchecked((int)0xFFFFFFFB);
/// The window's horizontal scroll bar.
public const int OBJID_HSCROLL = unchecked((int)0xFFFFFFFA);
/// The window's size grip: an optional frame component located at the lower-right corner of the window frame.
public const int OBJID_SIZEGRIP = unchecked((int)0xFFFFFFF9);
/// The text insertion bar (caret) in the window.
public const int OBJID_CARET = unchecked((int)0xFFFFFFF8);
/// The mouse pointer. There is only one mouse pointer in the system, and it is not a child of any window.
public const int OBJID_CURSOR = unchecked((int)0xFFFFFFF7);
///
/// An alert that is associated with a window or an application. System provided message boxes are the only UI elements that
/// send events with this object identifier. Server applications cannot use the AccessibleObjectFromX functions with this object
/// identifier. This is a known issue with Microsoft Active Accessibility.
///
public const int OBJID_ALERT = unchecked((int)0xFFFFFFF6);
///
/// A sound object. Sound objects do not have screen locations or children, but they do have name and state attributes. They are
/// children of the application that is playing the sound.
///
public const int OBJID_SOUND = unchecked((int)0xFFFFFFF5);
///
/// An object identifier that Oleacc.dll uses internally. For more information, see Appendix F: Object Identifier Values for OBJID_QUERYCLASSNAMEIDX.
///
public const int OBJID_QUERYCLASSNAMEIDX = unchecked((int)0xFFFFFFF4);
///
/// In response to this object identifier, third-party applications can expose their own object model. Third-party applications
/// can return any COM interface in response to this object identifier.
///
public const int OBJID_NATIVEOM = unchecked((int)0xFFFFFFF0);
}
/// Provides a for that is disposed using .
public class SafeHHOOK : SafeHANDLE, IUserHandle
{
/// Initializes a new instance of the class and assigns an existing handle.
/// An object that represents the pre-existing handle to use.
///
/// to reliably release the handle during the finalization phase; otherwise, (not recommended).
///
public SafeHHOOK(IntPtr preexistingHandle, bool ownsHandle = true) : base(preexistingHandle, ownsHandle) { }
/// Initializes a new instance of the class.
private SafeHHOOK() : base() { }
/// Performs an implicit conversion from to .
/// The safe handle instance.
/// The result of the conversion.
public static implicit operator HHOOK(SafeHHOOK h) => h.handle;
///
protected override bool InternalReleaseHandle() => UnhookWindowsHookEx(this);
}
}
}