Lancer et integrer un .exe dans une appli .net ?

Résolu
kaervas Messages postés 51 Date d'inscription vendredi 25 novembre 2005 Statut Membre Dernière intervention 19 avril 2008 - 17 mars 2008 à 12:17
kaervas Messages postés 51 Date d'inscription vendredi 25 novembre 2005 Statut Membre Dernière intervention 19 avril 2008 - 17 mars 2008 à 18:37
Bonjour,
Je suis en train de developper un programme en C#/.net 3.5 et j'aimerais lancer un .exe et integrer son processus ET son affichage graphique à l'intérieur de mon appli...
Sauriez vous si cela est eventuellement possible ?

4 réponses

Lutinore Messages postés 3246 Date d'inscription lundi 25 avril 2005 Statut Membre Dernière intervention 27 octobre 2012 41
17 mars 2008 à 14:44
Salut, si tu connais un peu l'API Win32 je pense que c'est possible, voila un point de départ ( beaucoup de code mais tu as juste à utiliser la methode ILoveNotepad ).

[ DllImport( "user32.dll", SetLastError = true ) ]
private static extern IntPtr SetParent( IntPtr hWndChild, IntPtr hWndNewParent );


[ DllImport( "user32.dll", SetLastError = true ) ] // 32 bits.
private static extern int GetWindowLong( IntPtr hWnd, int nIndex );


[ DllImport( "user32.dll", SetLastError = true ) ] // 64 bits.
private static extern IntPtr GetWindowLongPtr( IntPtr hWnd, int nIndex );


[ DllImport( "user32.dll", SetLastError = true ) ] // 32 bits.
private static extern int SetWindowLong( IntPtr hWnd, int nIndex, int dwNewLong );


[ DllImport( "user32.dll", SetLastError = true ) ] // 64 bits.
private static extern IntPtr SetWindowLongPtr( IntPtr hWnd, int nIndex, IntPtr dwNewLong );


private const int WS_POPUP = unchecked( ( int )0x80000000 );
private const int WS_CHILD = 0x40000000;
private const int GWL_STYLE = -16;


private void ILoveNotepad( )
{
    Process p = Process.Start( "notepad.exe" );
    p.WaitForInputIdle( 2000 );
    IntPtr hWnd = p.MainWindowHandle;
    p.Close( );
    p = null;


    int styles = ( int )GetStyles( hWnd );
    styles &= ~WS_POPUP;
    styles |= WS_CHILD;
    SetStyles( hWnd, ( IntPtr )styles );


    SetParent( hWnd, this.Handle );


    // WM_CHANGEUISTATE
    // WM_UPDATEUISTATE


    // etc..
}


private IntPtr GetStyles( IntPtr hWnd )
{
    if ( IntPtr.Size == 8 ) // 64 bits.
        return GetWindowLongPtr( hWnd, GWL_STYLE );
    else // 32bits
        return ( IntPtr )GetWindowLong( hWnd, GWL_STYLE );
}


private void SetStyles( IntPtr hWnd, IntPtr styles )
{
    if ( IntPtr.Size == 8 ) // 64 bits.
        SetWindowLongPtr( hWnd, GWL_STYLE, styles );
    else // 32 bits.
        SetWindowLong( hWnd, GWL_STYLE, ( int )styles );
}
3
kaervas Messages postés 51 Date d'inscription vendredi 25 novembre 2005 Statut Membre Dernière intervention 19 avril 2008
17 mars 2008 à 18:02
Merci pour ta réponse, je ne m'y connais pas trop en API windows, le processus se lance bien dans le handle, mais il n'y a pas les evenements (actualisation etc..) ?
0
Lutinore Messages postés 3246 Date d'inscription lundi 25 avril 2005 Statut Membre Dernière intervention 27 octobre 2012 41
17 mars 2008 à 18:18
Ce n'est qu'un point de départ.. après j'ai mis en commentaire les messages à envoyer WM_CHANGEUISTATE, WM_UPDATEUISTATE etc.. Il n'existe pas de fonctions managées pour faire ce genre de chose.
0
kaervas Messages postés 51 Date d'inscription vendredi 25 novembre 2005 Statut Membre Dernière intervention 19 avril 2008
17 mars 2008 à 18:37
D'accord merci, je dois un peu faire le boulot du kernel en gros ?
Par contre comment faire si je veux changer le repertoire courant du programme lancé ? (il n'est pas dans le meme dossier que l'appli qui le lance)
0
Rejoignez-nous