From 4a21ac34b92fcd1dde988cbf2e879530db1436de Mon Sep 17 00:00:00 2001 From: lilium-saber Date: Tue, 17 Oct 2023 21:33:24 +0800 Subject: [PATCH] 0 --- src/WinOcr/OcrSofia.cs | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/WinOcr/OcrSofia.cs b/src/WinOcr/OcrSofia.cs index 0215070..69f5582 100644 --- a/src/WinOcr/OcrSofia.cs +++ b/src/WinOcr/OcrSofia.cs @@ -28,6 +28,41 @@ namespace WpfApp1.WinOcr retxt = modiImage.Layout.Text; */ return retxt; + /* + string processName = "notepad"; // 替换为要跟踪的进程名称 + Process[] processes = Process.GetProcessesByName(processName); + if (processes.Length > 0) + { + Process process = processes[0]; + IntPtr hwnd = process.MainWindowHandle; + var Ocr = new IronTesseract(); + OcrResult Result = null; + Ocr.TextAvailable += (s, e) => + { + Console.WriteLine(e.Text); + Result = e.Result; + }; + while (true) + { + if (hwnd != IntPtr.Zero) + { + int length = GetWindowTextLength(hwnd); + if (length > 0) + { + IntPtr buffer = Marshal.AllocHGlobal(length + 1); + GetWindowText(hwnd, buffer, length + 1); + string text = Marshal.PtrToStringAnsi(buffer); + Marshal.FreeHGlobal(buffer); + Ocr.Read(text); + } + } + } + } + else + { + Console.WriteLine("找不到进程:{0}", processName); + } + */ } public void DirExists()