I am working with a Finger Print Sensor by ZkTeco. The below code in WFA works fine and the input from Finger Print Sensor is captured successfully.
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;
}
But the alternative in WPF below code doesn't work.
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);
}
}
}
While Debugging the function is being called but the Switch statement MESSAGE_CAPTURED_OK
never becomes true. What could be the reason ?