Esempio n. 1
0
        private WindowHookProc _hookProc; // Keep a reference to prevent garbage collection.

        public WindowHook(WindowHookType type)
        {
            _hookProc = new WindowHookProc(HookProc);

            _handle = SetWindowsHookEx(
                (int)type,
                _hookProc,
                IntPtr.Zero,
                AppDomain.GetCurrentThreadId()
                );
        }
Esempio n. 2
0
        private WindowHookProc _hookProc; // Keep a reference to prevent garbage collection.

        public WindowHook(WindowHookType type)
        {
            _hookProc = new WindowHookProc(HookProc);

            _handle = SetWindowsHookEx(
                (int)type,
                _hookProc,
                IntPtr.Zero,
                AppDomain.GetCurrentThreadId()
            );
        }
Esempio n. 3
0
        public static IntPtr SetWindowsHook(HookType hookType, WindowHookProc lpfnHookProc)
        {
            try
            {
                using (var currentProcess = Process.GetCurrentProcess())
                {
                    using (var currentModule = currentProcess.MainModule)
                    {
                        IntPtr hModule = Win32HookAPI.GetModuleHandle(currentModule.ModuleName);
                        if (hModule != IntPtr.Zero)
                        {
                            return(Win32HookAPI.SetWindowsHookEx(hookType, lpfnHookProc, hModule, 0));
                        }
                    }
                }
            }
            catch (System.Exception ex)
            {
                LocalStaticLogger.WriteLine(ex.ToString());
            }

            return(IntPtr.Zero);
        }
Esempio n. 4
0
 private static extern IntPtr SetWindowsHookEx(int hookId, WindowHookProc callback, IntPtr hInstance, int nativeThreadId);
Esempio n. 5
0
 internal static extern IntPtr SetWindowsHookEx(HookType hookType, WindowHookProc pfn, IntPtr hMod, uint dwThreadId);
Esempio n. 6
0
 public AsyncWindowsHook(HookType hookType, WindowHookProc pfnClientHookProc)
     : base(hookType, pfnClientHookProc)
 {
 }
Esempio n. 7
0
 private static extern IntPtr SetWindowsHookEx(int hookId, WindowHookProc callback, IntPtr hInstance, int nativeThreadId);
Esempio n. 8
0
 // passed-in routine used for call-back
 public WindowsHook(HookType hookType, WindowHookProc pfnClientHookProc)
 {
     this.hookType          = hookType;
     this.pfnClientHookProc = pfnClientHookProc;
     SetWindowsHook();
 }