private static extern IntPtr SetWindowsHookEx(int idHook, HookProc lpfn, IntPtr hInstance, int threadId);
public static void Register() { if (MessageBoxManager.hHook != IntPtr.Zero) { throw new NotSupportedException("One hook per thread allowed."); } MessageBoxManager.hHook = MessageBoxManager.SetWindowsHookEx(12, MessageBoxManager.hookProc, IntPtr.Zero, AppDomain.GetCurrentThreadId()); }