1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
|
//Class qui lance le programme externe dans un panel : ici notepad++
public class ProcessOxymetre
{
//Attributs
private Process p;
public Panel panelOxymetre;
//Constructeur
public ProcessOxymetre()
{
initPanel();
}
//Ajout de la fonction SetParent de l'API user32
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
//Initialisation du panel : taille, position ...
public void initPanel()
{
panelOxymetre = new System.Windows.Forms.Panel();
panelOxymetre.SuspendLayout();
//...
}
public void afficherPanelOxymetre()
{
panelOxymetre.ResumeLayout(false);
panelOxymetre.PerformLayout();
panelOxymetre.Show();
panelOxymetre.Visible = true;
}
public void lauchNotePad()
{
try
{
p = null;
string targetDir;
targetDir = string.Format(@"C:\Program Files\Notepad++");
p = new Process();
p.StartInfo.WorkingDirectory = targetDir;
p.StartInfo.FileName = "nppIExplorerShell.exe";
p.StartInfo.CreateNoWindow = true;
p.Start();
Win32.SetParent(p.MainWindowHandle, panelOxymetre.Handle);
p.WaitForExit();
}
catch (Exception ex)
{
MessageBox.Show("Erreur : "+ex.ToString(), "Erreur", MessageBoxButtons.OK, MessageBoxIcon.Stop);
}
}
}
//Class avec la form principale
public class frmMainWindow : Form
{
ProcessOxymetre pOxy;
public frmMainWindow()
{
InitializeComponent();
//Init panel && ajout a la form
pOxy = new ProcessOxymetre();
this.Controls.Add(pOxy.panelOxymetre);
}
//Clique sur bouton de lancement du pgm externe
private void btn_clicked(object sender, EventArgs e)
{
//On lance notepad++ et on rend visible le panel
pOxy.lauchNotePad();
pOxy.afficherPanelOxymetre();
}
} |
Partager