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

VB.NET Discussion :

Recuperer PID Word XP


Sujet :

VB.NET

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre éclairé Avatar de ac/dc
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Août 2006
    Messages
    369
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 38
    Localisation : France

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : Industrie

    Informations forums :
    Inscription : Août 2006
    Messages : 369
    Par défaut Recuperer PID Word XP
    Bonjour,

    J'ai un problème lors de l’exécution d'un logiciel.

    Cette application lance Word 2002 (XP) sur la machine. Puis on ouvre un document Word via cette application, mais avant, on récupère le PID de Word via cette ligne :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
     
    If Me.wordWnd = 0 Then
         Me.wordWnd = Me.FindWindow("Opusapp", "Microsoft Word")
    End If

    Le problème est que de temps en temps, la variable wordWnd reste à 0, donc Word n'est pas trouvé alors qu'il est bien ouvert dans la barre des tâches. Ce qui est étrange, c'est que le problème est aléatoire ...

    Quelqu'un a t-il une idée ?
    Merci

  2. #2
    Membre extrêmement actif
    Inscrit en
    Avril 2008
    Messages
    2 573
    Détails du profil
    Informations personnelles :
    Âge : 65

    Informations forums :
    Inscription : Avril 2008
    Messages : 2 573
    Par défaut Find the Window Handle for an Application That Can Have Multiple Instances
    bonjour ac/dc
    Il y aurait une petite erreur dans l'ordre des parametres de la fonction API FindWind(ByVal lpClassName As String, ByVal lpWindowName As String) As Long.
    Pour les applications Office a multiple instance comme Excel et Word,il faut fournir un "caption" ou titre de fenetre propre à chaque instance apres lancement de l'appli ,ensuite FindWindow attend ce caption comme 2eme parametre .
    Seul moyen d'identifier plusieurs instance de l'application par l'API.
    En quittant l'application il faut restaurer le caption de Microsoft.

    exemple code MSDN
    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
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
     
    Imports Microsoft.Office.Interop.Word
    Public Class Form3
        Dim wordApp1 As Microsoft.Office.Interop.Word.Application
        Dim wordApp2 As Microsoft.Office.Interop.Word.Application
        Public Sub New()
     
            ' Cet appel est requis par le Concepteur Windows Form.
            InitializeComponent()
     
            ' Ajoutez une initialisation quelconque après l'appel InitializeComponent().
            Me.TopMost = True
        End Sub
     
     
     
        Private Sub btnInstance1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnInstance1.Click
            wordApp1 = New Microsoft.Office.Interop.Word.Application
     
            'le caption identifiant cette instance
            wordApp1.Caption = "New Caption Supplied by Program Instance 1"
            'window handle
            Dim HwndWord As Long
            HwndWord = FindWindow("OpusApp", wordApp1.Caption)
     
     
            wordApp1.Visible = True
            Me.TextBox1.Text = Me.TextBox1.Text & _
            "HwndWord ( " & Hex(HwndWord) & " ) contains the Window Handle " & _
                 "of the Word application created by this program." & vbCr & _
                 "You can use this Window Handle in various Win 32 APIs, " & _
                 "such as SetForeGroundWindow," & vbCr & _
                 "which require a Window Handle parameter to be supplied." & vbCr _
                 & vbCr & "All Done. "
     
     
        End Sub
        Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
    (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
     
        Private Sub btnInstance2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnInstance2.Click
            wordApp2 = New Microsoft.Office.Interop.Word.Application
            'le caption identifiant cette instance
            wordApp2.Caption = "New Caption Supplied by Program Instance 2"
     
            'window handle
            Dim HwndWord As Long
            HwndWord = FindWindow("OpusApp", wordApp2.Caption) 'window handle
     
            wordApp2.Visible = True
            Me.TextBox2.Text = Me.TextBox2.Text & _
            "hWndXl ( " & Hex(HwndWord) & " ) contains the Window Handle " & _
                   "of the Word application created by this program." & vbCr & _
                   "You can use this Window Handle in various Win 32 APIs, " & _
                   "such as SetForeGroundWindow," & vbCr & _
                   "which require a Window Handle parameter to be supplied." & vbCr _
                   & vbCr & "All Done.  ."
     
     
     
        End Sub
     
        Private Sub btnCloseWordApps_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCloseWordApps.Click
            If wordApp1 IsNot Nothing Then
                wordApp1.Caption = String.Empty 'Set the original caption back
                wordApp1.Quit()
                wordApp1 = Nothing
            End If
            If wordApp2 IsNot Nothing Then
                wordApp2.Caption = String.Empty 'Set the original caption back
                wordApp2.Quit()
                wordApp2 = Nothing
            End If
        End Sub
     
        Private Sub Form3_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
            If wordApp1 IsNot Nothing Then
                wordApp1.Caption = String.Empty 'Set the original caption back
                wordApp1.Quit()
                wordApp1 = Nothing
            End If
            If wordApp2 IsNot Nothing Then
                wordApp2.Caption = String.Empty 'Set the original caption back
                wordApp2.Quit()
                wordApp2 = Nothing
            End If
        End Sub
    End Class
    BON CODE...........

Discussions similaires

  1. recuperer pid d'un script batch en execution
    Par grandtix dans le forum Windows XP
    Réponses: 2
    Dernier message: 24/07/2007, 18h18
  2. Recuperation de pid
    Par cox38 dans le forum Linux
    Réponses: 10
    Dernier message: 04/07/2005, 07h43
  3. [reseaux] récupération de pid
    Par eitrith dans le forum Programmation et administration système
    Réponses: 2
    Dernier message: 31/05/2004, 01h50
  4. Réponses: 2
    Dernier message: 19/01/2004, 12h19
  5. recuperation PID
    Par phoulosof dans le forum POSIX
    Réponses: 2
    Dernier message: 26/08/2002, 13h00

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