Ejemplo n.º 1
0
 public void InstallHook(Form window)
 {
     if (this.State == HookState.Uninstalled)
     {
         if (window != null)
         {
             NativeExports.SetLastError(0);
             IntPtr nextWindow = NativeExports.SetClipboardViewer(window.Handle);
             if (nextWindow == IntPtr.Zero)
             {
                 var errorCode = NativeExports.GetLastError();
                 if (errorCode == 0)
                 {
                     OnSuccessfullHook(window.Handle, nextWindow);
                 }
                 else
                 {
                     var message = ErrorCodeHelper.GetMessage(errorCode);
                     throw new Exception(message);
                 }
             }
             else
             {
                 OnSuccessfullHook(window.Handle, nextWindow);
             }
         }
     }
 }
Ejemplo n.º 2
0
 public void RemoveHook()
 {
     if (this.State == HookState.Installed)
     {
         if (NativeExports.UnhookWindowsHookEx(this.handle))
         {
             this.OnSuccessfullUnhook();
         }
         else
         {
             var errorCode = NativeExports.GetLastError();
             throw new Exception(ErrorCodeHelper.GetMessage(errorCode));
         }
     }
 }
Ejemplo n.º 3
0
 public void InstallHook(Form window)
 {
     if (this.State == HookState.Uninstalled)
     {
         this.keyboardProcessor = new KeyboardMessageEventHandler(KeyboardProc);
         this.handle            = NativeExports.SetWindowsHookEx(NativeConstants.WH_KEYBOARD_LL, this.keyboardProcessor, IntPtr.Zero, 0);
         if (this.handle == IntPtr.Zero)
         {
             this.keyboardProcessor = null;
             var errorCode = NativeExports.GetLastError();
             throw new Exception(ErrorCodeHelper.GetMessage(errorCode));
         }
         else
         {
             this.OnStateChanged(new StateChangedEventArgs(this.State));
         }
     }
 }
Ejemplo n.º 4
0
 public void RemoveHook()
 {
     if (this.State == HookState.Installed)
     {
         NativeExports.SetLastError(0);
         NativeExports.ChangeClipboardChain(this.clipboard.Handle, this.clipboard.NextWindow);
         var errorCode = NativeExports.GetLastError();
         if (errorCode == 0)
         {
             this.OnSuccessfullUnhook();
         }
         else
         {
             var message = ErrorCodeHelper.GetMessage(errorCode);
             throw new Exception(message);
         }
     }
 }