BSOne.SFC/Tocsg.Module/MonSecu/ThdCollectScreenInfo.pas

94 lines
2.2 KiB
Plaintext

{*******************************************************}
{ }
{ ThdCollectScreenInfo }
{ }
{ Copyright (C) 2022 kku }
{ }
{*******************************************************}
unit ThdCollectScreenInfo;
interface
uses
Tocsg.Thread, System.SysUtils, System.Classes, Winapi.Windows;
type
PMonSecuEnt = ^TMonSecuEnt;
TMonSecuEnt = record
sMonTxt: String;
end;
TThdCollectScreenInfo = class(TTgThread)
private
dwInterval_: DWORD;
protected
procedure Execute; override;
public
Constructor Create;
end;
function ExtrTxtFromDesktop: String;
implementation
uses
Tocsg.Capture, Tocsg.Path, Tocsg.Exception, Tocsg.Safe, Tocsg.Process;
const
DIR_TASK = 'Temp\';
EXE_OCR = 'Windows.Media.Ocr.Cli.exe';
function ExtrTxtFromDesktop: String;
var
sCurDir,
sImgPath,
sTxtPath: String;
fs: TFileStream;
bResult: Boolean;
StrList: TStringList;
begin
Result := '';
sCurDir := GetRunExePathDir;
sImgPath := sCurDir + DIR_TASK;
if FileExists(sCurDir + EXE_OCR) and
ForceDirectories(sImgPath) then
begin
sImgPath := sImgPath + FormatDateTime('yyyymmhhnnss', Now) + '.jpg';
try
fs := TFileStream.Create(sImgPath, fmCreate);
bResult := CaptureDesktopAsJpegStream(fs);
fs.Free;
if bResult then
begin
sTxtPath := sImgPath + '.txt';
ExecuteAppWaitUntilTerminate(sCurDir + EXE_OCR, Format('"%s" "%s"', [sImgPath, sTxtPath]), SW_HIDE, 60000);
if FileExists(sTxtPath) then
begin
Guard(StrList, TStringList.Create);
StrList.LoadFromFile(sTxtPath, TEncoding.UTF8);
Result := StrList.Text;
DeleteFile(PChar(sTxtPath));
end;
DeleteFile(PChar(sImgPath));
end;
except
on E: Exception do
ETgException.TraceException(E, 'Fail .. ExtrTxtFromDesktop()');
end;
end;
end;
{ TThdCollectScreenInfo }
Constructor TThdCollectScreenInfo.Create;
begin
Inherited Create;
end;
procedure TThdCollectScreenInfo.Execute;
begin
end;
end.