IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

C# Discussion :

Donner le focus à une application externe


Sujet :

C#

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Candidat au Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Juin 2013
    Messages
    2
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Juin 2013
    Messages : 2
    Par défaut Donner le focus à une application externe
    Bonsoir !

    Alors voici, mon problème est tout simple.
    Je cherche avec mon application à "activer" ou "donner le focus" (comme vous préférez) à une application externe. C'est à dire ?
    C'est à dire que j'ai une application déjà lancée (dans la barre des tâches, sous la forme "réduite"), et je cherche à faire comme si je cliquais dessus et que je faisais "agrandir".

    Avec mon application, je ne dispose que du nom et de l'id de l'application en cours. Je n'ai pas trouvé de méthode tel que MonAppli.Active() et je n'ai rien trouvé sur internet non plus.. En esperant que vous pourrez m'aider !

    Bonne soirée,
    Betize.

  2. #2
    Membre Expert

    Homme Profil pro
    Développeur .NET
    Inscrit en
    Novembre 2010
    Messages
    2 067
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Développeur .NET

    Informations forums :
    Inscription : Novembre 2010
    Messages : 2 067
    Par défaut
    En faisant du Pinvoke avec la méthode showwindow tyu peux faire ça :
    http://www.pinvoke.net/default.aspx/user32.showwindow
    Il te faut juste l'handle de la fenêtre

  3. #3
    Candidat au Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Juin 2013
    Messages
    2
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Juin 2013
    Messages : 2
    Par défaut
    Merci, il me semble que c'est ce que je cherchais !
    Seulement..
    Parameters

    hWnd [in]

    Type: HWND

    A handle to the window.
    Comment obtenir ceci ?

  4. #4
    Membre Expert

    Homme Profil pro
    Développeur .NET
    Inscrit en
    Novembre 2010
    Messages
    2 067
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Développeur .NET

    Informations forums :
    Inscription : Novembre 2010
    Messages : 2 067
    Par défaut
    Dans la class process tu as différentes méthodes pour obtenir les différents processus en cours d’exécution par nom, par id :
    http://msdn.microsoft.com/fr-fr/libr...s_methods.aspx
    Une fois ton process récupéré tu as la propriété MainWindowHandle que tu utilisera pour la méthode ShowWindow.

    Un exemple avec notepad en c#
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
     [DllImport("user32.dll")]
            private static extern bool ShowWindow(IntPtr hWnd, WindowShowStyle nCmdShow);
     
            /// <summary>Enumeration of the different ways of showing a window using
            /// ShowWindow</summary>
            private enum WindowShowStyle : uint
            {
                /// <summary>Hides the window and activates another window.</summary>
                /// <remarks>See SW_HIDE</remarks>
                Hide = 0,
                /// <summary>Activates and displays a window. If the window is minimized
                /// or maximized, the system restores it to its original size and
                /// position. An application should specify this flag when displaying
                /// the window for the first time.</summary>
                /// <remarks>See SW_SHOWNORMAL</remarks>
                ShowNormal = 1,
                /// <summary>Activates the window and displays it as a minimized window.</summary>
                /// <remarks>See SW_SHOWMINIMIZED</remarks>
                ShowMinimized = 2,
                /// <summary>Activates the window and displays it as a maximized window.</summary>
                /// <remarks>See SW_SHOWMAXIMIZED</remarks>
                ShowMaximized = 3,
                /// <summary>Maximizes the specified window.</summary>
                /// <remarks>See SW_MAXIMIZE</remarks>
                Maximize = 3,
                /// <summary>Displays a window in its most recent size and position.
                /// This value is similar to "ShowNormal", except the window is not
                /// actived.</summary>
                /// <remarks>See SW_SHOWNOACTIVATE</remarks>
                ShowNormalNoActivate = 4,
                /// <summary>Activates the window and displays it in its current size
                /// and position.</summary>
                /// <remarks>See SW_SHOW</remarks>
                Show = 5,
                /// <summary>Minimizes the specified window and activates the next
                /// top-level window in the Z order.</summary>
                /// <remarks>See SW_MINIMIZE</remarks>
                Minimize = 6,
                /// <summary>Displays the window as a minimized window. This value is
                /// similar to "ShowMinimized", except the window is not activated.</summary>
                /// <remarks>See SW_SHOWMINNOACTIVE</remarks>
                ShowMinNoActivate = 7,
                /// <summary>Displays the window in its current size and position. This
                /// value is similar to "Show", except the window is not activated.</summary>
                /// <remarks>See SW_SHOWNA</remarks>
                ShowNoActivate = 8,
                /// <summary>Activates and displays the window. If the window is
                /// minimized or maximized, the system restores it to its original size
                /// and position. An application should specify this flag when restoring
                /// a minimized window.</summary>
                /// <remarks>See SW_RESTORE</remarks>
                Restore = 9,
                /// <summary>Sets the show state based on the SW_ value specified in the
                /// STARTUPINFO structure passed to the CreateProcess function by the
                /// program that started the application.</summary>
                /// <remarks>See SW_SHOWDEFAULT</remarks>
                ShowDefault = 10,
                /// <summary>Windows 2000/XP: Minimizes a window, even if the thread
                /// that owns the window is hung. This flag should only be used when
                /// minimizing windows from a different thread.</summary>
                /// <remarks>See SW_FORCEMINIMIZE</remarks>
                ForceMinimized = 11
            }
     
     
            private void button1_Click(object sender, EventArgs e)
            {
                Process[] process = Process.GetProcessesByName("Notepad");
                if (process != null && process.Length > 0)
                {
                    bool result = ShowWindow(process[0].MainWindowHandle, WindowShowStyle.ShowMaximized);
                }
            }

Discussions similaires

  1. Réponses: 12
    Dernier message: 23/01/2008, 09h17
  2. [VB]donner le focus à une application déja ouverte ou fermée
    Par Nicko29 dans le forum VB 6 et antérieur
    Réponses: 17
    Dernier message: 21/01/2006, 14h28
  3. [Excel] Utiliser une application externe par une macro
    Par thierry2.dlp dans le forum Macros et VBA Excel
    Réponses: 4
    Dernier message: 09/08/2005, 22h07
  4. "Mettre le focus" à une application à partir de son Handle
    Par Tardiff Jean-François dans le forum Composants VCL
    Réponses: 2
    Dernier message: 04/07/2005, 08h54

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo