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 : 9467
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} 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 ...

{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...

{Visual Basic, VB6, VB.NET, VB 2005} CAPTEUR DE HANDLE, DE TITRE, DE CLASS, DE POSITION DE TAILLE ET DE PATH
Ayant eu besoin de trouver des Handles pour mon programme de carnet d'adresses: http://www.vbfrance....

{PHP} RÉCUPÉRER LE TYPE D'UN FICHIER (3 FONCTIONS DIFFÉRENTES)
Bonjour à tous, La plupart des gens pense que récupérer l'extension d'un fichier envoyé par form...

{Visual Basic, VB6, VB.NET, VB 2005} DATE-HEURE DE LANCEMENT D'UN PROGRAMME
Retrouver la date et l'heure à laquelle a été lancé un programme. Je devais développer cette recher...

{Visual Basic, VB6, VB.NET, VB 2005} RECUPERER ET AFFICHER LES MESSAGES D'INFORMATION ET D'ERREUR EN PROVENANCE DU SERVEUR SQL
Cette source permet la connexion à une base de données SQL recuperer l'ensemble tes tables de la BD...

{Visual Basic, VB6, VB.NET, VB 2005} YET ANOTHER (REMOTE) PROCESS MONITOR
Bonjour à tous, YAPM (Yet Another (remote) Process Monitor) est un programme de monitoring avancé...

{JAVA / J2EE} JADE PAR LA PRATIQUE
Présentation de l'application: C'est une petite application java qui a pour but de récupérer un obj...