using System; using System.Diagnostics; using System.IO; using System.Runtime.InteropServices; using System.Net; using System.Net.Sockets; using System.Text; using System.Threading; using System.Collections; using System.Collections.Generic; namespace SPC.Kiosk.Common { public static class AiScannerProcess { [DllImport("user32.dll")] static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent); [DllImport("user32.dll")] private static extern IntPtr FindWindow(string SClassName, string SWindowName); [DllImport("user32.dll")] private static extern bool SetForegroundWindow(IntPtr findname); [DllImport("user32.dll")] private static extern bool ShowWindowAsync(IntPtr findname, int howShow); [DllImport("user32.dll")] private static extern bool BringWindowToTop(IntPtr findname); [DllImport("user32.dll")] static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags); static readonly IntPtr HWND_TOPMOST = new IntPtr(-1); const UInt32 SWP_NOSIZE = 0x0001; const UInt32 SWP_NOMOVE = 0x0002; const UInt32 SWP_SHOWWINDOW = 0x0040; private static Process AiScannerExe = null; private static readonly string ip = "127.0.0.1"; private static readonly int port = 11004; private static Thread listenThread; private static Thread recevieThread; private static Socket clientSocket; private static Socket listenSocket; public static bool Excuted { get { if (AiScannerExe != null) { return !AiScannerExe.HasExited; } else { return false; } } } public static void ExcuteAiScanner(IntPtr _openner) { try { if (Excuted || AiScannerExe != null) StopAiScanner(); var fileName = Path.Combine(ResourceManager.BinPath, CommonValue.AiScannerPath); if (File.Exists(fileName)) { var newStartInfo = new ProcessStartInfo { FileName = fileName, UseShellExecute = false, //WindowStyle= ProcessWindowStyle.Hidden, ErrorDialog = false, CreateNoWindow = true, }; AiScannerExe = new Process(); AiScannerExe.StartInfo = newStartInfo; if (AiScannerExe.Start()) { AiScannerExe.WaitForInputIdle(500); SetParent(AiScannerExe.MainWindowHandle, _openner); //AiScannerExe.StartInfo.WindowStyle = ProcessWindowStyle.Normal; //StartListening(); } } else { CommonLog.ErrorLogWrite("SPC.Kiosk.Common", "AiScannerProcess", "ExcuteAiScanner()", "File Not Exists !!", string.Format("\nFile Path: {0}", fileName)); } } catch (Exception ex) { CommonLog.ErrorLogWrite("SPC.Kiosk.Common", "AiScannerProcess", "ExcuteAiScanner()", "Fail !!", string.Format("{0}\n{1}", ex.Message, ex.StackTrace)); } } public static void StopAiScanner() { if (Excuted) { AiScannerExe.Kill(); AiScannerExe.WaitForExit(); AiScannerExe.Dispose(); AiScannerExe = null; } else { if (AiScannerExe != null) AiScannerExe = null; } } } }