基线:全量源码首提(D1 版本控制落地,含第一轮优化 B1-B4/A1/A4/缩放修复)
This commit is contained in:
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
* MainForm:主窗体(报价工具 + PDF 查看器)
|
||||
* 由 cadbt 改造:WebView2 网页 CAD → pdfium 原生 PDF 查看 + 框选 OCR
|
||||
*/
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace pdfbt
|
||||
{
|
||||
public partial class MainForm : Form
|
||||
{
|
||||
public MainForm()
|
||||
{
|
||||
InitializeComponent();
|
||||
CreateDockWindows_dockSurface1();
|
||||
|
||||
// ★ 全局 F1/F2/F3 过滤器:焦点在任何 WinForms 控件上都触发元件合并
|
||||
// (与 cadbt 一致,两路都汇聚到 PdfBridge.F*Requested)
|
||||
Application.AddMessageFilter(new F1MessageFilter());
|
||||
FormClosed += (s, e) => Application.RemoveMessageFilter(f1Filter);
|
||||
|
||||
// ★ Umi-OCR 预热:已装本体且当前引擎为 umi 时,主程序一启动就静默拉起
|
||||
// (--hide 托盘),不等首次框选;后台线程跑,不拖慢窗口出现
|
||||
System.Threading.ThreadPool.QueueUserWorkItem(_ =>
|
||||
{
|
||||
try
|
||||
{
|
||||
if (File.Exists(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "baidu_ocr.json")))
|
||||
{
|
||||
var jsv = new System.Web.Script.Serialization.JavaScriptSerializer()
|
||||
.Deserialize<System.Collections.Generic.Dictionary<string, string>>(
|
||||
File.ReadAllText(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "baidu_ocr.json")));
|
||||
string eng = jsv != null && jsv.ContainsKey("engine") ? jsv["engine"] : "baidu";
|
||||
if (eng == "umi" && UmiOcrHost.IsInstalled) UmiOcrHost.EnsureRunning();
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
});
|
||||
}
|
||||
|
||||
private readonly F1MessageFilter f1Filter = new F1MessageFilter();
|
||||
|
||||
/// <summary>
|
||||
/// 把 F1/F2/F3 按键(0x70/0x71/0x72)转成 PdfBridge 事件。
|
||||
/// ★ 焦点在报价插件(Form3)树内时不触发——那条路径由 Form3.ProcessCmdKey
|
||||
/// 处理,此处再触发会双跑一次(F1 合并两遍:第一遍成功、第二遍弹
|
||||
/// "请先选中至少2行"的误提示)。
|
||||
/// </summary>
|
||||
private class F1MessageFilter : IMessageFilter
|
||||
{
|
||||
public bool PreFilterMessage(ref Message m)
|
||||
{
|
||||
const int WM_KEYDOWN = 0x0100;
|
||||
bool isFKey = m.Msg == WM_KEYDOWN &&
|
||||
((int)m.WParam == 0x70 || (int)m.WParam == 0x71 || (int)m.WParam == 0x72);
|
||||
if (!isFKey) return false;
|
||||
|
||||
// 焦点控件在 Form3 树内 → 交给 Form3.ProcessCmdKey,跳过
|
||||
try
|
||||
{
|
||||
var focused = Control.FromHandle(m.HWnd);
|
||||
for (var c = focused; c != null; c = c.Parent)
|
||||
{
|
||||
if (c is MyApp.Form3) return false;
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
|
||||
int key = (int)m.WParam;
|
||||
try
|
||||
{
|
||||
if (key == 0x70) PdfBridge.RaiseF1();
|
||||
else if (key == 0x71) PdfBridge.RaiseF2();
|
||||
else if (key == 0x72) PdfBridge.RaiseF3();
|
||||
}
|
||||
catch { }
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user