mirror of
https://github.com/soukoku/ntwain.git
synced 2025-12-19 19:57:02 +08:00
Attempt to resurrect my old triplet ideas with new data types and native methods.
This commit is contained in:
51
samples/WinForm32/Form1.cs
Normal file
51
samples/WinForm32/Form1.cs
Normal file
@@ -0,0 +1,51 @@
|
||||
using NTwain;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Reflection;
|
||||
using System.Windows.Forms;
|
||||
using TWAINWorkingGroup;
|
||||
|
||||
namespace WinForm32
|
||||
{
|
||||
public partial class Form1 : Form
|
||||
{
|
||||
private TwainSession twain;
|
||||
|
||||
public Form1()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
InitTwain();
|
||||
}
|
||||
|
||||
private void InitTwain()
|
||||
{
|
||||
TwainPlatform.PreferLegacyDSM = true;
|
||||
|
||||
twain = new TwainSession(Assembly.GetExecutingAssembly().Location);
|
||||
twain.StateChanged += Twain_StateChanged;
|
||||
|
||||
}
|
||||
|
||||
private static void Twain_StateChanged(TwainSession session, TWAINWorkingGroup.STATE state)
|
||||
{
|
||||
Console.WriteLine($"State changed to {state}");
|
||||
}
|
||||
|
||||
protected override void OnHandleCreated(EventArgs e)
|
||||
{
|
||||
base.OnHandleCreated(e);
|
||||
|
||||
|
||||
var hwnd = this.Handle;
|
||||
var rc = twain.DGControl.Parent.OpenDSM(ref hwnd);
|
||||
Debug.WriteLine($"OpenDSM={rc}");
|
||||
|
||||
if (rc == TWAINWorkingGroup.STS.SUCCESS)
|
||||
{
|
||||
Debug.WriteLine($"CloseDSM={rc}");
|
||||
rc = twain.DGControl.Parent.CloseDSM(ref hwnd);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user