WPF 中使用Hook

public DocumentWindow()
      {
          InitializeComponent();
  this.SourceInitialized += new EventHandler(OnSourceInitialized);
      }
      void OnSourceInitialized(object sender, EventArgs e)
      {
          HwndSource source = (HwndSource)PresentationSource.FromVisual(this);
          source.AddHook(new HwndSourceHook(HandleMessages));
      }
      private IntPtr HandleMessages(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
      {
          //KeyboardHook  一个钩子类
          KeyboardHook hk = new KeyboardHook();
          hk.KeyDown += new System.Windows.Forms.KeyEventHandler(kh_KeyDown);
          return System.IntPtr.Zero;
      }
 
 
      void kh_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
      {
          if (e.KeyCode == Keys.F5)
          {
              System.Windows.Forms.MessageBox.Show("f5");
              e.Handled = true;
              Microsoft.Office.Interop.PowerPoint._Presentation myPres =
                (Microsoft.Office.Interop.PowerPoint.Presentation)framer.ActiveDocument;
              myPres.SlideShowSettings.RangeType = PpSlideShowRangeType.ppShowSlideRange;
              var mm = myPres.SlideShowSettings;
              var app = myPres.Application;
              mm.Run();
          }
          else if (e.KeyCode == Keys.Escape)
          {
              //System.Windows.Forms.MessageBox.Show("退?出?");
              e.Handled = true;
              this.Close();
          }
          if (e.KeyCode == Keys.Right)
          {
             // e.Handled = true;
             // Microsoft.Office.Interop.PowerPoint._Presentation myPres =
             //  (Microsoft.Office.Interop.PowerPoint.Presentation)framer.ActiveDocument;
             // myPres.SlideShowSettings.RangeType = PpSlideShowRangeType.ppShowSlideRange;
             // var mm = myPres.SlideShowSettings;
             // mm.LoopUntilStopped=Microsoft.Office.Core.MsoTriState.msoTrue;
             myPres.SlideShowWindow.View.LastSlideViewed
              var app = myPres.Application;
             // mm.Run();
          }
          //if (e.KeyCode == Keys.F1 && !fInCall)
          //{
          //    e.Handled = true;
          //    fInCall = true;
          //    tmrDelayedCall = new Timer();
          //    tmrDelayedCall.Interval = 1;
          //    tmrDelayedCall.Tick += new
          //    EventHandler(tmrDelayedCall_Tick);
          //    tmrDelayedCall.Start();
          //}
      }
 

 

hook 类实现 IDisposable接口

转载于:https://www.cnblogs.com/z_lb/archive/2011/03/28/1997758.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值