C#WPF WndProc消息捕获不起作用

时间:2019-02-25 05:23:45

标签: c# wpf zkteco

我正在使用ZkTeco的指纹传感器。 WFA中的以下代码可以正常工作,并且可以成功捕获指纹传感器的输入。

   protected override void DefWndProc(ref Message m)
    {
        switch (m.Msg)
        {
            case MESSAGE_CAPTURED_OK:
                {
                    MemoryStream ms = new MemoryStream();
                    BitmapFormat.GetBitmap(FPBuffer, mfpWidth, mfpHeight, ref ms);
                    Bitmap bmp = new Bitmap(ms);
                    this.picFPImg.Image = bmp;
                    if (IsRegister)
                    {  
                      // Logic here  
                    }
                 }
          }
            default:
                base.DefWndProc(ref m);
                break;
      }  

但是WPF下面代码中的替代方法不起作用。

    HwndSource source;
    protected override void OnSourceInitialized(EventArgs e)
    {
        var window = Application.Current.MainWindow;

        base.OnSourceInitialized(e);
        if (window != null)
        {
            HwndSource source = PresentationSource.FromVisual(window) as HwndSource;

            source?.AddHook(WndProc);
        }
    }
   private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
    {
        switch (msg)
        {
            case MESSAGE_CAPTURED_OK:
                {
                    MemoryStream ms = new MemoryStream();
                    BitmapFormat.GetBitmap(FPBuffer, mfpWidth, mfpHeight, ref ms);
                 }
         }
     }  

虽然正在调试函数,但是Switch语句MESSAGE_CAPTURED_OK永远不会变为true。可能是什么原因?

0 个答案:

没有答案