• 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接口

  • 相关阅读:
    JVM参数默认值列表
    垃圾回收G1日志解析
    《深入理解JAVA虚拟机》垃圾回收时为什么会停顿
    《深入理解JAVA虚拟机》JDK的垃圾收集算法
    什么才是技术?
    Lodash使用示例(比较全)
    MSCL超级工具类(C#),开发人员必备,开发利器
    刷新SqlServer数据库中所有的视图
    Sql Server 2014/2012/2008/2005 数据库还原出现 3154错误的解决办法
    C#中执行批处理文件(.bat),执行数据库相关操作
  • 原文地址:https://www.cnblogs.com/z_lb/p/1997758.html
Copyright © 2020-2023  润新知