Process / Handle [Résolu]

Vous débutez et vous avez besoin d'aide ? N'hésitez pas à poser vos questions
Avatar de l’utilisateur
Kwai chang caine
Messages : 6989
Inscription : sam. 23/sept./2006 18:32
Localisation : Isere

Process / Handle [Résolu]

Message par Kwai chang caine »

Bonjour les copains :D

Voila, j'utilise ce code de ORYAAAAA pour savoir si une fenetre existe et il marche tres bien.

Code : Tout sélectionner

Procedure.b CheckRunningExe(FileName.s) 
  Protected snap.l , Proc32.PROCESSENTRY32 , dll_kernel32.l 
  FileName = GetFilePart( FileName ) 
  dll_kernel32 = OpenLibrary (#PB_Any, "kernel32.dll") 
  If dll_kernel32 
    snap = CallFunction (dll_kernel32, "CreateToolhelp32Snapshot",$2, 0) 
    If snap 
      Proc32\dwSize = SizeOf (PROCESSENTRY32) 
      If CallFunction (dll_kernel32, "Process32First", snap, @Proc32) 
        While CallFunction (dll_kernel32, "Process32Next", snap, @Proc32) 
          If PeekS (@Proc32\szExeFile)=FileName 
            CloseHandle_ (snap) 
            CloseLibrary (dll_kernel32) 
            ProcedureReturn #True 
          EndIf 
        Wend 
      EndIf    
      CloseHandle_ (snap) 
    EndIf 
    CloseLibrary (dll_kernel32) 
  EndIf 
  ProcedureReturn #False 
EndProcedure 

Debug CheckRunningExe("Word.exe")
Le probleme, c'est qu'il ne retourne que 0 ou 1.
Et moi j'aurais voulu qu'il me retourne le handle, afin que je puisse minimiser/maximiser la fenetre dans la barre de taches

J'ai bien fouiné dans toute la structure de la variable PROCESSENTRY32, mais rien ne correspond au handle dont je me sert dab dans la fonction

Code : Tout sélectionner

ShowWindow_(WindowID(#XXX), #SW_SHOWMINIMIZED) ; Minimiser la fenêtre
Si "quinquin" a une idée :roll:
Merci et bonne journée
Dernière modification par Kwai chang caine le mar. 13/mai/2008 17:32, modifié 1 fois.
Anonyme

Message par Anonyme »

ORYAAAAA = pirate
la droopylib te permet de faire cela , GetHandle() je crois
Avatar de l’utilisateur
Kwai chang caine
Messages : 6989
Inscription : sam. 23/sept./2006 18:32
Localisation : Isere

Message par Kwai chang caine »

Bonjour mon copain CPL :D
Content de te causer
ORYAAAAA = pirate
Pourquoi pirate, un vrai :D
Avec le bandeau et la jambe de bois :lol:

Qu'est ce qu'il a fait de vilain ????
la droopylib te permet de faire cela , GetHandle() je crois
Bah, je suis pas tres lib :oops:
J'ai rien contre leur createur, c'est genial, mais juste pour une fonction, c'est un peu dommage d'installer une lib.
En plus ce code enumere tous les process, donc il doit fatalement voir les handles, non ????

D'ailleurs c'est aussi pour progresser que je posais cete question, car il doit surement avoir un autre code "non pirate" qui enumere les handles et nom de fenetres.
Mais je trouvais interessant de connaitre la liaison entre ces deux valeurs, si il y en a une bien sur :roll:

Un handle, j'avais a peu pres compris que c'etait le numero qu'attribuais windows a tout objet ou presque afin de le reconnaitre, mais c'est quoi au juste le process ???? :roll:

Ils se connaissent ces deux la ????? ou bien ils mangent pas à la meme table :lol:
Avatar de l’utilisateur
Kwai chang caine
Messages : 6989
Inscription : sam. 23/sept./2006 18:32
Localisation : Isere

Message par Kwai chang caine »

Bon je continuais a chercher et j'ai trouvé un code qui parle pas de process, il est de SFSxOI
J'espere qu'il est pas pirate lui non plus :? .......:lol:
http://www.purebasic.fr/english/viewtop ... 616#222616

Code : Tout sélectionner

; will return the correct hWnd for a PID if the PiD only runs a single thread. 
; for apps that run more then one thread will return the handle from the first thread belonging to the PiD 
; which may not be the handle you want. 

Procedure InstanceToWnd(target_pid.l) 
;Find the first window 
test_hwnd = FindWindow_(0,0) 
While test_hwnd <> 0 
  ;Check If the window isn't a child 
        If GetParent_(test_hwnd) = 0 ;Then 
          ;Get the window's thread 
            test_thread_id = GetWindowThreadProcessId_(test_hwnd, @test_pid) 
              If test_pid = target_pid ;Then 
                InstanceToWnd = test_hwnd 
                Break ;Exit Do 
              EndIf 
        EndIf 
        ;retrieve the Next window 
        test_hwnd = GetWindow_(test_hwnd, #GW_HWNDNEXT) 
Wend 
ProcedureReturn test_hwnd 
EndProcedure 
Ca marche, mais bon reste le point d'interrogation sur les process :roll:
Backup
Messages : 14526
Inscription : lun. 26/avr./2004 0:40

Message par Backup »

Kwai chang caine a écrit : Ca marche, mais bon reste le point d'interrogation sur les process :roll:
un process c'est un prg qui occupe la memoire
tu en vois une partie en faisant Ctrl+Alt+Del :D

voici un prg qui liste les process


Code : Tout sélectionner

; English forum: http://purebasic.myforums.net/viewtopic.php?t=8086&highlight=
; Author: Hi-Toro (updated for PB3.93 by Andre)
; Date: 29. October 2003
; OS: Windows
; Demo: No
; Should run correctly on WinXP, Win2000/2003 - will not work correctly on Win98 and older...
; Look for ListRunningProcesses_withHierrachy_W9x.pb to get a version for Win95 and newer.
; -----------------------------------------------------------------------------
; Shows list of running processes and their hierarchy...
; -----------------------------------------------------------------------------
; james @ hi - toro . com
; -----------------------------------------------------------------------------

; -----------------------------------------------------------------------------
; Constants required by process functions, etc...
; -----------------------------------------------------------------------------
#TH32CS_SNAPHEAPLIST = $1
#TH32CS_SNAPPROCESS = $2
#TH32CS_SNAPTHREAD = $4
#TH32CS_SNAPMODULE = $8
#TH32CS_SNAPALL = #TH32CS_SNAPHEAPLIST | #TH32CS_SNAPPROCESS | #TH32CS_SNAPTHREAD | #TH32CS_SNAPMODULE
#TH32CS_INHERIT = $80000000
#INVALID_HANDLE_VALUE = -1
#MAX_PATH = 260
#PROCESS32LIB = 9999
; -----------------------------------------------------------------------------
; GLOBAL PROCESS LIST! Used to retrieve information after getting process list...
; -----------------------------------------------------------------------------
Global NewList Proc32.PROCESSENTRY32 ()
; -----------------------------------------------------------------------------
; kernel32.dll open/close...
; -----------------------------------------------------------------------------
Procedure InitProcess32 ()
    ProcedureReturn OpenLibrary (#PROCESS32LIB, "kernel32.dll")
EndProcedure

Procedure CloseProcess32 ()
    ProcedureReturn CloseLibrary (#PROCESS32LIB)
EndProcedure
; -----------------------------------------------------------------------------
; Get/free snapshot of process list...
; -----------------------------------------------------------------------------
Procedure CreateProcessList ()
    ClearList (Proc32 ())
    ProcedureReturn CallFunction (#PROCESS32LIB, "CreateToolhelp32Snapshot", #TH32CS_SNAPPROCESS, 0)
EndProcedure
Procedure FreeProcessList (snapshot)
    ; Free process list (.PROCESSENTRY32 structures)...
    ClearList (Proc32 ())
    ; Close snapshot handle...
    ProcedureReturn CloseHandle_ (snapshot)
EndProcedure
; -----------------------------------------------------------------------------
; Iterate processes...
; -----------------------------------------------------------------------------
Procedure GetFirstProcess (snapshot)
    ; Allocate a new .PROCESSENTRY32 structure and fill in SizeOf (structure)...
    AddElement (Proc32 ())
    Proc32 ()\dwSize = SizeOf (PROCESSENTRY32)
    ; Call Process32First with snapshot handle and pointer to structure...
    If CallFunction (#PROCESS32LIB, "Process32First", snapshot, @Proc32 ())
        ProcedureReturn #True
    Else
        ; Free the structure if function call failed...
        DeleteElement (Proc32 ())
        ProcedureReturn #False
    EndIf
EndProcedure
Procedure GetNextProcess (snapshot)
    ; Allocate a new .PROCESSENTRY32 structure and fill in SizeOf (structure)...
    AddElement (Proc32 ())
    Proc32 ()\dwSize = SizeOf (PROCESSENTRY32)
    ; Call Process32Next with snapshot handle and pointer to structure...
    If CallFunction (#PROCESS32LIB, "Process32Next", snapshot, @Proc32 ())
        ProcedureReturn #True
    Else
        ; Free the structure if function call failed...
        DeleteElement (Proc32 ())
        ProcedureReturn #False
    EndIf
EndProcedure
; -----------------------------------------------------------------------------
; Another PROCESSENTRY32 list for destructive operations on process list...
; -----------------------------------------------------------------------------
Global NewList Proc32Copy.PROCESSENTRY32 ()
; Copy Proc32 () into Proc32Copy ()...
Procedure CopyProcessList ()
    ResetList (Proc32 ())
    While NextElement (Proc32 ())
        AddElement (Proc32Copy ())
        CopyMemory (@Proc32 (), @Proc32Copy (), SizeOf (PROCESSENTRY32))
    Wend
EndProcedure
; Free Proc32Copy () list when done with it...
Procedure FreeProcessListCopy ()
    ClearList (Proc32Copy ())
EndProcedure
; By the wonders of trial and error, we have this (this recursively adds
; processes to supplied TreeGadget)... don't ask me to explain this (see
; 'trial and error' comment... ;)

Procedure AddTreeProcesses (gadget, currentid) ; currentid = Proc32Copy ()\th32ProcessID 
    ; Iterate through copy of Proc32 () -- call CopyProcessList () to get this... 
    ResetList (Proc32Copy ()) 
    While NextElement (Proc32Copy ()) 
        ; Skip if checking against 'currentid', ie. same process... 
        If Proc32Copy ()\th32ProcessID <> currentid 
            ; Check currentid against this one... 
            againstid = Proc32Copy ()\th32ProcessID
            againstparent = Proc32Copy ()\th32ParentProcessID 
            ; If 'currentid' is parent of this process... 
            If currentid = againstparent 
                ; We have a child process. Open a new node in the TreeGadget... 
               ;  OpenTreeGadgetNode (gadget) 
                ; Note: next line uses GetFilePart () as the Win9x \szExeFile contains full path (WinNT has filename only)! 
                AddGadgetItem (gadget, -1, GetFilePart (PeekS (@Proc32Copy ()\szExeFile))) 
                ; Store current position in Proc32Copy () list... 
                current = ListIndex (Proc32Copy ()) 
                ; Recursive function call to iterate against all other processes (ow, head hurts)... 
                AddTreeProcesses (gadget, againstid) 
                ; Go back to stored position in list... 
                SelectElement (Proc32Copy (), current) 
                ; Delete element so we don't process it again... 
                DeleteElement (Proc32Copy ()) 
                ; OK, close the new TreeGadget node... 
               ; CloseTreeGadgetNode (gadget) 
            EndIf 
        EndIf 
    Wend 
EndProcedure
; Window callback procedure (resizes TreeGadget on window resize)...
Procedure WindowCallback (WindowID, message, wParam, lParam)
    Select message
        Case #WM_SIZE
            ResizeGadget (0, 0, 0, WindowWidth (0), WindowHeight (0))
    EndSelect
    ProcedureReturn #PB_ProcessPureBasicEvents
EndProcedure

; Create basic window and gadget list...
OpenWindow (0, 0, 0, 320, 300, "List of running processes...",#PB_Window_SystemMenu | #PB_Window_MaximizeGadget | #PB_Window_MinimizeGadget | #PB_Window_SizeGadget | #PB_Window_ScreenCentered)
CreateGadgetList (WindowID (0))
; Create TreeGadget...
TreeGadget (0, 0, 0, WindowWidth (0), WindowHeight (0))
; Create root node in TreeGadget...
;OpenTreeGadgetNode (0)
; Start window callback procedure...
SetWindowCallback (@WindowCallback ())
; About to add list of processes to TreeGadget...
; -----------------------------------------------------------------------------
; Initialise process list stuff (really just opening kernel32.dll!)...
; -----------------------------------------------------------------------------
If InitProcess32 () 
    ; -------------------------------------------------------------------------
    ; Get a snapshot of all running processes...
    ; ------------------------------------------------------------------------- 
    snapshot = CreateProcessList () 
    If snapshot 
        ; ---------------------------------------------------------------------
        ; Get list of processes (generates the Proc32 () list)...
        ; --------------------------------------------------------------------- 
        If GetFirstProcess (snapshot)
            Repeat
                result = GetNextProcess (snapshot)
            Until result = #False
        EndIf 
        ; ---------------------------------------------------------------------
        ; Copy Proc32 () as Proc32Copy (), so we can do nasty things to data...
        ; --------------------------------------------------------------------- 
        ; Note that in this particular example, we don't need to operate on Proc32 ()
        ; after creating the list, but I'm making a copy because you need to delete elements
        ; when adding to the TreeGadget so that you don't repeatedly compare against
        ; previously elements already added. If we needed to operate on the Proc32 ()
        ; list later, this way would mean it's still available... 
        CopyProcessList () 
        ; ---------------------------------------------------------------------
        ; Iterate through Proc32Copy () list, and act on process data here...
        ; --------------------------------------------------------------------- 
        ResetList (Proc32Copy ()) 
        While NextElement (Proc32Copy ()) 
            ; Add new item to root node... 
            AddGadgetItem (0, -1, GetFilePart (PeekS (@Proc32Copy ()\szExeFile))) 
            ; Store current position in Proc32Copy () list... 
            current = ListIndex (Proc32Copy ()) 
            ; Iterate through the Proc32Copy () list (recursive function)... 
            AddTreeProcesses (0, Proc32Copy ()\th32ProcessID) 
            ; Go back to where we were in the list... 
            SelectElement (Proc32Copy (), current) 
        Wend 
        ; ---------------------------------------------------------------------
        ; Free copy of process list...
        ; --------------------------------------------------------------------- 
        FreeProcessListCopy () 
        ; ---------------------------------------------------------------------
        ; Free snapshot/list of processes...
        ; --------------------------------------------------------------------- 
        FreeProcessList (snapshot) 
    EndIf 
    ; -------------------------------------------------------------------------
    ; Close kernel32.dll...
    ; ------------------------------------------------------------------------- 
    CloseProcess32 () 
EndIf
; -----------------------------------------------------------------------------
; Event loop...
; -----------------------------------------------------------------------------
Repeat
Until WaitWindowEvent () = #PB_Event_CloseWindow
End
Anonyme

Message par Anonyme »

oui ORYAAAAA est un "niak" (excusé mon langage) qui c'est vanté d'avoir une version de pb piraté il me semble.
C'est l'admin du site purebasic chinois ou coréen... , bref du soleil levant quoi...
Avatar de l’utilisateur
Kwai chang caine
Messages : 6989
Inscription : sam. 23/sept./2006 18:32
Localisation : Isere

Message par Kwai chang caine »

Merci DOBRO

Mais alors un PROCESS a forcément un handle, ou j'ai encore dit une connerie :oops:
oui ORYAAAAA est un "niak" (excusé mon langage) qui c'est vanté d'avoir une version de pb piraté il me semble.
C'est l'admin du site purebasic chinois ou coréen... , bref du soleil levant quoi...
Ba bravo, admin d'un site sur un giciel piraté, et en plus a 400 balles. :lol:

Moi j'adore les asiatiques et tout ce qu'il génere, savoir, santé, nourriture, technologie, etc .......
Mais la , t'as raison, "l'es vilain ce tchong :? "
Avatar de l’utilisateur
Kwai chang caine
Messages : 6989
Inscription : sam. 23/sept./2006 18:32
Localisation : Isere

Message par Kwai chang caine »

Je relance ce POST, car je n'avais pas eu de reponse.

Y'a un peu cafouillage dans ma tete entre les handles et les process.

Moi j'ai compris ça :

Code : Tout sélectionner

Chaque application qui se lance dans windows a un PROCESS
A son tour elle a des fenetres, boutons etc ....qui ont chacun un handle
Est ce que j'ai bien compris ????
Est ce qu'un aplli peut aussi avoir un handle ????
Ou un objet un process ???

Merci d'eclairer mon obscur chemin :cry:
Le Soldat Inconnu
Messages : 4312
Inscription : mer. 28/janv./2004 20:58
Localisation : Clermont ferrand OU Olsztyn
Contact :

Message par Le Soldat Inconnu »

Tu as compris

Une application --> Process
Des fenetres, gadgets etc associé au process (donc ton programme)
Et les fenêtres et gadgets sont numéroté par Windows, ce numéro s'apelle Handle. Un peu comme le numéro sur ta carte d'identité.
Tu crée un objet, Windows lui donne un nom sous forme de Handle

et si c'est pas ça, c'est que j'ai rien compris moi aussi :lol:
Je ne suis pas à moitié Polonais mais ma moitié est polonaise ... Vous avez suivi ?

[Intel quad core Q9400 2.66mhz, ATI 4870, 4Go Ram, XP (x86) / 7 (x64)]
Avatar de l’utilisateur
Kwai chang caine
Messages : 6989
Inscription : sam. 23/sept./2006 18:32
Localisation : Isere

Message par Kwai chang caine »

Merci bien enfin des trucs qui rentrent dans mon "Godiwok" (Cerveau dans Orange mecanique) :D

Donc si on parle d'un handle, c'est pas une appli.
Et une appli n'a jamais de handle, mais un PID, c'est a dire un Process Identifier

Ouuuaaahhh, qu'est ce que c'est bon de comprendre......
J'en profite, c'est tellement rare :D

Merci de ton explication
Avatar de l’utilisateur
Fortix
Messages : 559
Inscription : mar. 30/mai/2006 17:03

Message par Fortix »

Handle = ID
, juste au passage :lol:
Répondre