Les Snippets

Connexion

Récupérer le hwnd (handle) à partir du PID (Process ID)

Niveau requis pour utiliser/comprendre cette source : 1 ( Débutant )
Créé le 10/09/2007 16:30:43 et initié par PCPT [Liste]
Date de mise à jour : 24/09/2008 11:46:25
Vue : 14024
Catégorie(s) : API
Langages dispo pour ce code :
- VB6, VBA
- Delphi 5



Langage : VB6 , VBA
Date ajout : 10/09/2007
Posté par PCPT [Liste]
DateMAJ : 24/09/2008
Private Const GW_HWNDNEXT As Long 2&
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As LongByVal lpWindowName As Long) As  Long
Private Declare Function GetParent Lib "user32" (ByVal hwnd As LongAs Long
Private Declare Function GetWindowThreadProcessId Lib  "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As  Long
Private Declare Function GetWindow Lib "user32" (ByVal hwnd As LongByVal wCmd As Long) As  Long
'
Public Function InstanceToWnd(ByVal target_pid As Long) As Long 'API-Guid
    Dim test_hwnd As Long, test_pid As Long, test_thread_id As  Long
    test_hwnd = FindWindow(ByVal 0&ByVal 0&)
    Do While test_hwnd <> 0&
        If GetParent(test_hwnd) = 0& Then
            test_thread_id = GetWindowThreadProcessId(test_hwnd,  test_pid)
            If test_pid = target_pid Then
                InstanceToWnd = test_hwnd
                Exit Do
            End If
        End If
        test_hwnd = GetWindow(test_hwnd, GW_HWNDNEXT)
    Loop
End Function

Remarque :
ce code provient de l'API-Guid
Langage : Delphi 5
Date ajout : 13/09/2007
Posté par cirec [Liste]
Function GetWindowFromID(ProcessID : Cardinal): THandle;
Var TestID  : Cardinal;
    TestHandle : Thandle;
Begin
  Result := 0;
  TestHandle := FindWindowEx(GetDesktopWindow, 0, Nil, Nil);
  While TestHandle > 0 do  Begin
      If GetParent(TestHandle) = 0 Then
        GetWindowThreadProcessId(TestHandle,  @TestID);
          If TestID = ProcessID Then  Begin
            Result := TestHandle;
            Exit;
          End;
      TestHandle := GetWindow(TestHandle, GW_HWNDNEXT)
  End;
End;

Remarque :
C'est une "traduction" du code de PCPT

Snippets en rapport avec : Handle, Process, Récupérer, Pid



Codes sources en rapport avec : Handle, Process, Récupérer, Pid

{Visual Basic, VB6, VB.NET, VB 2005} RÉCUPÉRER PID PROCESSUS, NOM DE FICHIER.EXE ET HANDLE FENÊTRE À PARTIR DE PID OU NOM DE FICHIER.EXE OU DE HANDLE FENÊTRE
6 fonctions pour processus. GetProcessPidByExeName, GetProcessPidByHwnd, GetProcessHwndByPid, GetPro...

{Visual Basic, VB6, VB.NET, VB 2005} YET ANOTHER PROCESS MONITOR
Bonjour à tous, YAPM (Yet Another Process Monitor) est un programme permettant d'entièrement gé...

{Visual Basic, VB6, VB.NET, VB 2005} PROCESS THREADS MODULES HANDLES DANS UN TREEVIEW EN .NET ( OUI MADAME )
Cette source est ma première tentative en vb .net. il faut savoir que j'ai pas la msdn .net... Qu'...

{Visual Basic, VB6, VB.NET, VB 2005} MANIPULATION DES PROCESS ET HANDLES - OPTIONS INÉDITES...
Bon ben comme d'habitude, il liste tous les programmes lancés sur l'ordi, même ceux qui sont cachés ...

{C# / C#.NET} SAVOIR QUEL FICHIER EST UTILISÉ PAR TELLE APPLICATION : LA LISTE DES FICHIERS OUVERTS SUR LE SYSTÈME (POUR 2K/XP/2K3/VISTA/SEVEN)
Ce code permet d'avoir la liste des fichiers ouverts sur le système. Il emploie des fonctions non do...

{C# / C#.NET} CONNAITRE LE PROCESS CONNECTÉ À VOS SOCKET
Permet de récupérer une instance de Process désignant l'application connecté à l'autre bout de vos S...

{Visual Basic, VB6, VB.NET, VB 2005} ENUMERATION DES PORTS TCP ET IDENTIFCATION DU PROCESS (PID) CONCERNÉ
Utilise une API non documentée dispo sur XP. Pas testé sur Vista et supérieurs... portage de: h...

{Delphi} OBSERVATEUR DE PROCESSUS ACTIFS; VPROCESS 1,0
Outil pour afficher les processus / applications qui s'exécutent sur l'ordinateur. Affiche des infor...

{C# / C#.NET} EXCEL SERVER
Qui n a pas rencontré ce problème d'Excel qui ne se termine pas correctement ? Ce projet a pour b...

{PDA / PocketPC} UN PETIT GESTIONNAIRE DE TACHE AVEC OPENNETCF
Voici un petit gestionnaire de tache écrit avec moins d'une centaine de ligne de code. Je l'ai fait...