句柄函数
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
#region 获取句柄,触发事件
// InPtr 平台整数类型,lpWindowName 窗体的标题
[DllImport("user32.dll", EntryPoint = "FindWindow", CharSet = CharSet.Auto)]
static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("user32.dll", EntryPoint = "FindWindowEx", CharSet = CharSet.Auto)]
extern static IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);
[DllImport("user32.dll", EntryPoint = "SendMessage")]
private static extern int SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, string lParam);
[DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
public static extern IntPtr GetForegroundWindow();
[DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
public static extern int ShowWindow(IntPtr hwnd, int nCmdShow);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern int MoveWindow(IntPtr hWnd, int x, int y, int nWidth, int nHeight, bool BRePaint);
private void TouchInptr()
{
//mAEvent.WaitOne();
string path = ClsCDGlobVar.strAppTempPath + @"/H/gridanalysis.exe";//"C:\\WINDOWS\\system32\\calc.exe";
//ProcessStartInfo startInfo = new ProcessStartInfo(path);
//startInfo.WindowStyle = ProcessWindowStyle.Hidden;
//startInfo.CreateNoWindow = true;
//Process p = Process.Start(startInfo);
//....
Process p = new Process();
p.StartInfo.FileName = path;
p.StartInfo.RedirectStandardOutput = true;
eShellExecute = false;
p.StartInfo.CreateNoWindow = true;
p.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
p.Start();
if (p == null)
MessageBox.Show("Warning:process may already exist");
IntPtr mainWindows = FindMainWindowHandle("接地网接地性能分析", 100, 25);
IntPtr MainWindow2 = FindMainWindowHandle("分析内容选择", 100, 25);
//MoveWindow(mainWindows, -1, -1, 0, 0, true);
//MoveWindow(MainWindow2, -1, -1, 0, 0, true);
Thread.Sleep(1000);
IntPtr Rdio2 = FindWindowByIndex(MainWindow2, 2);
IntPtr butSure = FindWindowEx(MainWindow2, (IntPtr)0, null, "确认");
if (butSure == IntPtr.Zero || Rdio2 == IntPtr.Zero)
{
throw new Exception("Unable to find 'butSure'");
}
else
{
//最小化窗口
//ShowWindow(mainWindows, 2);
//ShowWindow(MainWindow2, 2);
SendMessage(Rdio2, 0x00F5, (IntPtr)0, null);
SendMessage(butSure, 0x00F5, (IntPtr)0, null);
}
IntPtr MainWindow3 = FindMainWindowHandle("接地网频域电磁场数值分析", 100, 25);
IntPtr InMX = FindWindowEx(MainWindow3, (IntPtr)0, null, "输入接地网结构、土壤模型");
IntPtr In = FindWindowEx(InMX, (IntPtr)0, null, "输入");
if (In == IntPtr.Zero)
throw new Exception("Unable to find 'In'");
else
{
//MoveWindow(MainWindow3, -1, -1, 0, 0, true);
SendMessage(In, 0x00F5, (IntPtr)0, null);
}
IntPtr MainWindow4 = FindMainWindowHandle("输入", 100, 25);
//MoveWindow(MainWindow4, -1, -1, 0, 0, true);
IntPtr Open = FindWindowEx(MainWindow4, (IntPtr)0, null, "打开");
//Rdio1
IntPtr InJD = FindWindowEx(MainWindow4, (IntPtr)0, null, "输入接地网结构及其参数");
IntPtr MXSD = FindWindowEx(InJD, (IntPtr)0, null, "计算模型设定");
IntPtr BDDW = FindWindowEx(MXSD, (IntPtr)0, null, "按不等电位模型计算");
//Rdio2 垂直
IntPtr InHD = FindWindowEx(MainWindow4, (IntPtr)0, null, "输入土壤各层的电阻率及其厚度");
IntPtr Choice = FindWindowEx(InHD, (IntPtr)0, null, "选择土壤结构");
IntPtr H = FindWindowEx(Choice, (IntPtr)0, null, "土壤沿竖直方向分层");