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 : 7477
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 ...

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

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

{C / C++ / C++.NET} [C/WIN32][DRIVER] DÉTECTION DE CRÉATION OU DE SUPPRESSION DE PROCESSUS.
Yop à tous, Voici un petite driver qui permet la détection de la création ou de la suppression d'...

{Visual Basic, VB6, VB.NET, VB 2005} COMMENT DÉTECTER LES PROCESSUS CACHÉS (VIRUS, ROOTKITS...) + ÉNUMÉRATION AVANCÉE DES PROCESSUS
Bonjour, voilà une source montrant comment avoir la liste des processus cachés qui tournent sur l...

{Delphi} CAMFROG HANDLES OP
Bonjour, J'ai eu l'idée de coder un outil me permettant d'administrer des fonctions de modération s...

{Visual Basic, VB6, VB.NET, VB 2005} ATTENDRE LA FIN D'UN PROCESS EXTERNE AVANT DE FAIRE AUTRE CHOSE
Voila, j'avais besoin de tester si un log (wordpad dans mon exemple) n'était plus en exécution avant...

{PHP} [PHP5] MULTI-THREADING : ACCÉLÉRATION DU TEMPS DE TRAVAIL D'UN SCRIPT.
L'article rédigé par Martin Roest (http://www.ibuildings.com/blog/archives/1539-Boost-performance-wi...