private void App_Exited(object sender, EventArgs e) { //关闭应用程序时,关闭相应的按钮 IntPtr handle = ((Process)sender).MainWindowHandle; Dispatcher.BeginInvoke(new Action(delegate { int buttonCount = appStackPanel.Children.Count; for (int i = 0; i < buttonCount; i++) { AppButton bt = (AppButton)appStackPanel.Children[i]; if (bt.handle_application == handle) { appStackPanel.Children.Remove(bt); MainWindow.intPtrs.Remove(handle); break; } } })); }
public void loadProcess(string proceddStr) { if (MainWindow.app_included) { Process process = Process.Start(proceddStr); if (process != null) { process.EnableRaisingEvents = true; process.Exited += App_Exited; handle_application = (IntPtr)0; while ((int)handle_application == 0) { handle_application = process.MainWindowHandle; } } else { //handle_application = FindWindow("Windows.UI.Core.CoreWindow", "Microsoft Edge"); } SetParent(handle_application, handle_panel); SetForegroundWindow(handle_application); SendMessage(handle_application, WM_SYSCOMMAND, SC_MAXIMIZE, 0); MainWindow.intPtrs.Add(handle_application); AppButton bt = new AppButton(handle_application); if (process != null) { bt.Content = process.ProcessName; } appStackPanel.Children.Add(bt); } else { Process process = Process.Start(proceddStr); //设置两个窗体的位置 } }
public void loadProcess(string proceddStr) { if (MainWindow.app_included) { string houzhui = proceddStr.Substring(proceddStr.LastIndexOf('.') + 1); Process process = Process.Start(proceddStr); //string str1=""; //Process myProcess = new Process(); //Process[] wordProcess; if (houzhui == "doc" || houzhui == "docx") { log_str = log_str + "正在打开word文件\r\n"; //do //{ // wordProcess = Process.GetProcessesByName("WinWord"); // log_str = log_str + "wordProcess.Length="+wordProcess.Length+"\r\n"; // try // { // log_str = log_str + "word进程数为:"+wordProcess.Length+"\r\n"; // foreach (Process pro in wordProcess) // { // str1 = pro.MainWindowTitle; // log_str = log_str + "进程名:" + str1 + "\r\n"; // } // } // catch (Exception ex) // { // MessageBox.Show(ex.Message); // } //} while (wordProcess.Length!=1); //log_str = log_str + "跳出打开循环" + "\r\n"; int time_waiting = 15 * 1000; var t1 = DateTime.Now.AddMilliseconds(time_waiting); while (DateTime.Now < t1) { DispatcherHelper.DoEvents(); } } if (process != null) { process.EnableRaisingEvents = true; process.Exited += App_Exited; handle_application = (IntPtr)0; while ((int)handle_application == 0) { handle_application = process.MainWindowHandle; } log_str = log_str + "process != null,handle_application=" + handle_application + "\r\n"; } else { var t = DateTime.Now.AddMilliseconds(2000); while (DateTime.Now < t) { DispatcherHelper.DoEvents(); } //handle_application = FindWindow("CabinetWClass", null); handle_application = GetForegroundWindow(); log_str = log_str + "process == null,handle_application=" + handle_application + "\r\n"; } SetParent(handle_application, handle_panel); SetForegroundWindow(handle_application); SendMessage(handle_application, WM_SYSCOMMAND, SC_MAXIMIZE, 0); MainWindow.intPtrs.Add(handle_application); AppButton bt = new AppButton(handle_application); if (process != null) { bt.Content = process.ProcessName; } } else { Process process = Process.Start(proceddStr); } //保存文件 logPath = MainWindow.path_database + "\\log.txt"; System.IO.StreamWriter sw = new System.IO.StreamWriter(logPath, true); sw.WriteLine(log_str); sw.Close(); }