private void startProcess(string name) { Process app = new Process(); app.StartInfo.FileName = name; app.StartInfo.CreateNoWindow = false; app.StartInfo.ErrorDialog = true; app.EnableRaisingEvents = true; app.Exited += new System.EventHandler(on_exit); app.Start(); app.WaitForExit(1 * 1000); if (app.HasExited) { MessageBox.Show("进程意外退出", "警告"); } else { updateProcesses(this, new EventArgs()); IntPtr appid = new IntPtr(app.Id); IntPtr handle; foreach (object ob in this.comboBox1.Items) { handle = ((MyComboBoxItem)ob).Handle; IntPtr pid = NativeUtils.GetProcessForWindow(handle); if (pid == appid) { this._targetHandle = handle; btOK.Enabled = true; } } } }
public override string ToString() { return(string.Format("[0]:{1}<{2}>", (int)NativeUtils.GetProcessForWindow(this.Handle), NativeUtils.GetWindowText(this._handle), NativeUtils.GetClassName(this._handle))); }
private bool ChangeSelectedObject(object selectedObject) { if (!CoreApplicationOptions.Instance.AllowSelectOwnedObjects) { if (selectedObject != null && selectedObject.GetType().Assembly == typeof(HawkeyeEditor).Assembly) { if (!(selectedObject is IAllowSelect)) { return(true); } } } try { propertyGrid.SelectedObject = selectedObject; PluginManager.Instance.OnSelectedObjectChanged(selectedObject); if (selectedObject != null) { string controlName = HawkeyeUtils.GetControlName(selectedObject); if ((controlName == null) || (controlName.Length == 0)) { Text = HawkeyeAppUtils.AppName + "(unknown object name)"; } else { Text = HawkeyeAppUtils.AppName + controlName; } txtType.Text = selectedObject.GetType().FullName; try { txtToString.Text = selectedObject.ToString(); } catch (Exception ex) { txtToString.Text = "<ex:>" + ex.Message; Trace.WriteLine("ChangeSelectedObject: selectedObjectToString:" + ex.ToString(), "Hawkeye"); } ShowTail(txtType); ShowTail(txtToString); return(true); } txtToString.Text = string.Empty; if (NativeUtils.IsTargetInDifferentProcess(this.windowFinder.SelectedHandle)) { if (windowFinder.IsManagedByClassName) { txtType.Text = "<target in different process. release selection to hook>"; //TODO: this always return true on x86 machines! bool flag = NativeUtils.IsProcessX64(NativeUtils.GetProcessForWindow(windowFinder.SelectedHandle)); Text = HawkeyeAppUtils.AppName + ".Net " + (flag ? "x64 " : "") + "Process"; } else { txtType.Text = "<target not in a managed process>"; Text = HawkeyeAppUtils.AppName + "not a managed process"; } } else { if (windowFinder.Window.IsValid) { txtToString.Text = "ClassName:" + this.windowFinder.Window.ClassName; } else { txtType.Text = "<no selection or unknown window>"; } Text = HawkeyeAppUtils.AppName; } return(false); } catch (Exception ex) { Trace.WriteLine(string.Concat(new object[] { "Exception activating object:", selectedObject, ":", ex.ToString() }), "Hawkeye"); txtType.Text = "Ex:" + ex.Message; txtToString.Text = ex.ToString().Replace("\r\n", "--"); return(true); } }