using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
namespace CADConverter.Provider
{
/// <summary>
/// 关闭CAD弹出的警告对话框,主要针对教育版本
/// </summary>
/// <remarks>
/// author: tryc 2013.07.09
/// </remarks>
public class CloseCadDialog
{
/// <summary>
/// 模拟鼠标点击
/// </summary>
/// <param name="swp"></param>
private void SimulateMouseClick(SimulateWindowPos swp)
{
string title = swp.Title;
IntPtr hwnd = FindWindow(null, title);
if (hwnd != IntPtr.Zero)
{
Rect rect;
GetWindowRect(hwnd, out rect);
SetWindowPos(hwnd, (IntPtr)HWND_TOPMOST, rect.Left, rect.Top, rect.Right - rect.Left, rect.Bottom - rect.Top, TOPMOST_FLAGS);
Rect lastRect = rect;
lastRect.Top = swp.Top;
lastRect.Left = swp.Left;
SetCursorPos(lastRect.Left, lastRect.Top);
mouse_event(MOUSEEVENTF_LEFTDOWN, lastRect.Left, lastRect.Top, 0, new IntPtr(0));
//mouse_event(MOUSEEVENTF_LEFTDOWN, lastRect.Left, lastRect.Top, 0, new IntPtr(0));
mouse_event(MOUSEEVENTF_LEFTUP, lastRect.Left, lastRect.Top, 0, new IntPtr(0));
}
}
/// <summary>
/// 开始干活,死循环检测打开的窗口
/// </summary>
/// <param name="jsonDialog">需要处理的对话框界面</param>
public void DoIt(string jsonDialog)
{
//LPTSTR lpPath = L"guard.ini";
var interval = Global.ProcessInterval;
List<SimulateWindowPos> swp = null;
if (string.IsNullOrWhiteSpace(jsonDialog))
{
swp = new List<SimulateWindowPos>
{
new SimulateWindowPos {Title = "教育版 - 检测到打印戳记", Top = 140, Left = 200, Sleep = interval*10},
new SimulateWindowPos {Title = "教育版 - 文件确认", Top = 126, Left = 365, Sleep = interval*3},
new SimulateWindowPos {Title = "打开 - 外来 DWG 文件", Top = 110, Left = 150, Sleep = interval*10},
new SimulateWindowPos {Title = "缺少语言包", Top = 110, Left = 150, Sleep = interval*3},
};
}
else
{
var ser = new System.Web.Script.Serialization.JavaScriptSerializer();
swp = ser.Deserialize<List<SimulateWindowPos>>(jsonDialog);
}
if (swp == null || swp.Count < 1)
{
return;
}
while (true)
{
foreach (var item in swp)
{
SimulateMouseClick(item);
Thread.Sleep(item.Sleep);
}
Thread.Sleep(interval);
}
}
}
}
网友评论
我要评论