Salve grazie per l'aiuto ho questo problem il programma che ho creato mi funziona perfettamente ma non come vorrei , vorrei aprire in contemporanea più programmi pero appena apro un altro mi scompare l'altro , esempio apro paint , poi click per apri il notepad e mi scompare paint
host è un WindowsFormsHost
host è un WindowsFormsHost
C#:
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using System.Threading;
using System.Reflection;
namespace Arca
{
/// <summary>
/// Logica di interazione per MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
[DllImport("user32.dll")]
static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
[DllImport("user32.dll", SetLastError = true)]
public static extern bool MoveWindow(IntPtr hWnd, int X, int Y, int nWidth, int nHeight, bool bRepaint);
private Process pDocked;
private IntPtr hWndOriginalParent;
private IntPtr hWndDocked;
public System.Windows.Forms.Panel pannel;
public System.Windows.Forms.Panel pannel_2;
public MainWindow()
{
InitializeComponent();
MediaElement_1.Height = Screen.PrimaryScreen.Bounds.Height;
MediaElement_1.Play();
/*
Bitmap myBitmap = new Bitmap();
Graphics g = Graphics.FromImage(myBitmap);
System.Drawing.Pen myPen = new System.Drawing.Pen(System.Drawing.Color.Red);
g.DrawRectangle(myPen, new System.Drawing.Rectangle(0, 300, 400, 400));
g.DrawImage(myBitmap, 1, 1);*/
}
private void Window_PreviewLostKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e)
{
Window window = (Window)sender;
window.Topmost = true;
}
private void Button_Home_Click(object sender, RoutedEventArgs e)
{
Cambia_Pagina(0);
}
private void Button_Dash_Click(object sender, RoutedEventArgs e)
{
Cambia_Pagina(1);
}
private void Button_Mondo_Click(object sender, RoutedEventArgs e)
{
Cambia_Pagina(2);
}
private void Button_Manuale_Click(object sender, RoutedEventArgs e)
{
Cambia_Pagina(4);
}
private void Button_Mappa_Click(object sender, RoutedEventArgs e)
{
Cambia_Pagina(3);
}
private void Button_Play_Click(object sender, RoutedEventArgs e)
{
pannel = new System.Windows.Forms.Panel();
host.Child = pannel;
System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.EnableRaisingEvents = false;
proc.StartInfo.FileName = "notepad.exe";
//proc.StartInfo.Arguments = "D:/(C)/neruale.py";
proc.Start();
proc.WaitForInputIdle();
while (proc.MainWindowHandle == IntPtr.Zero)
{
Thread.Sleep(100); // Don't hog the CPU
proc.Refresh(); // You need this since `MainWindowHandle` is cached
}
SetParent(proc.MainWindowHandle, pannel.Handle);
/*
Process p = Process.Start("notepad.exe");
p.WaitForInputIdle();
while (p.MainWindowHandle == IntPtr.Zero)
{
Thread.Sleep(100); // Don't hog the CPU
p.Refresh(); // You need this since `MainWindowHandle` is cached
}
SetParent(p.MainWindowHandle, pannel.Handle);
*/
}
private void Button_Image_Click(object sender, RoutedEventArgs e)
{
//pannelo = new System.Windows.Forms.Panel();
host.Child = pannel;
System.Diagnostics.Process proco = new System.Diagnostics.Process();
proco.EnableRaisingEvents = false;
proco.StartInfo.FileName = "C:/Program Files/Internet Explorer/iexplore.exe";
proco.StartInfo.Arguments = "www.google.it";
proco.Start();
proco.WaitForInputIdle();
while (proco.MainWindowHandle == IntPtr.Zero)
{
Thread.Sleep(100); // Don't hog the CPU
proco.Refresh(); // You need this since `MainWindowHandle` is cached
}
SetParent(proco.MainWindowHandle, pannel.Handle);
/*
pannel = new System.Windows.Forms.Panel();
host.Child = pannel;
dockIt("mspaint.exe");*/
}
private void Button_Paint_Click(object sender, RoutedEventArgs e)
{
pannel = new System.Windows.Forms.Panel();
host.Child = pannel;
System.Diagnostics.Process proc_1 = new System.Diagnostics.Process();
proc_1.EnableRaisingEvents = false;
proc_1.StartInfo.FileName = "mspaint.exe";
proc_1.Start();
proc_1.WaitForInputIdle();
while (proc_1.MainWindowHandle == IntPtr.Zero)
{
Thread.Sleep(100); // Don't hog the CPU
proc_1.Refresh(); // You need this since `MainWindowHandle` is cached
}
SetParent(proc_1.MainWindowHandle, pannel.Handle);
/*System.Diagnostics.Process pProcess = new System.Diagnostics.Process();
pProcess.StartInfo.FileName = "C:/Users/Salvatore/AppData/Local/Programs/Python/Python37/python.exe";
pProcess.StartInfo.Arguments = "D:/(C)/neruale.py"; //argument
pProcess.StartInfo.UseShellExecute = false;
pProcess.StartInfo.RedirectStandardOutput = true;
pProcess.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
pProcess.StartInfo.CreateNoWindow = true; //not diplay a windows
pProcess.Start();
pProcess.WaitForExit();*/
}
private void ListBox_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{
Info_Galleria.Source = null;
}
private void ListBox1_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{
ListBox.Items.Clear();
if (ListBox.SelectedIndex == 1)
ListBox.Items.Add("1111");
if (ListBox.SelectedIndex == 8)
ListBox.Items.Add("Crediti");
}
private void Button_CMD_Click(object sender, RoutedEventArgs e)
{
pannel = new System.Windows.Forms.Panel();
host.Child = pannel;
Process pp = Process.Start("cmd.exe");
//pp.WaitForInputIdle();
SetParent(pp.MainWindowHandle, pannel.Handle);
}
private void Button_Click(object sender, RoutedEventArgs e)
{
pannel_2 = new System.Windows.Forms.Panel();
host.Child = pannel_2;
System.Diagnostics.Process proc_2 = new System.Diagnostics.Process();
proc_2.EnableRaisingEvents = false;
proc_2.StartInfo.FileName = "notepad.exe";
proc_2.Start();
proc_2.WaitForInputIdle();
while (proc_2.MainWindowHandle == IntPtr.Zero)
{
Thread.Sleep(100); // Don't hog the CPU
proc_2.Refresh(); // You need this since `MainWindowHandle` is cached
}
SetParent(proc_2.MainWindowHandle, pannel_2.Handle);
}
// ----- END -----
}
}
Ultima modifica: