|
-
Jan 10th, 2002, 10:56 AM
#1
Thread Starter
Hyperactive Member
Process ID and Handles
I have the processid to a program(the result returned when I shell something). I want to get its handle. How do I accomplish this?? Thank you very much for the help.
Joe
-
Jan 10th, 2002, 11:48 AM
#2
Fanatic Member
Code:
Option Explicit
Public Declare Function GetWindow Lib "user32" _
(ByVal hwnd As Long, ByVal wCmd As Long) As Long
Public Declare Function GetDesktopWindow Lib "user32" () As Long
Public Declare Function GetWindowThreadProcessId Lib "user32" _
(ByVal hwnd As Long, lpdwProcessId As Long) As Long
Public Declare Function BringWindowToTop Lib "user32" _
(ByVal hwnd As Long) As Long
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA"
_
(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam
As Any) As Long
Public ProcessID As Long
Public Const WM_CLOSE = &H10
Public Const GW_HWNDFIRST = 0
Public Const GW_HWNDNEXT = 2
Public Const GW_CHILD = 5
Public Function hWndFromProcessID(ProcID As Long) As Long
Dim TempHandle As Long
Dim GWTPIReturn As Long
Dim CurrentProcID As Long
On Error GoTo errHandler
TempHandle = GetDesktopWindow()
TempHandle = GetWindow(TempHandle, GW_CHILD)
Do While TempHandle <> 0
GWTPIReturn = GetWindowThreadProcessId(TempHandle,
CurrentProcID)
If CurrentProcID = ProcID Then
hWndFromProcessID = TempHandle
Exit Do
End If
TempHandle = GetWindow(TempHandle, GW_HWNDNEXT)
Loop
Exit Function
errHandler:
TempHandle = 0
End Function
Crispin
VB6 ENT SP5
VB.NET
W2K ADV SVR SP3
WWW.BLOCKSOFT.CO.UK
[Microsoft Basic: 1976-2001, RIP]
-
Jan 10th, 2002, 12:05 PM
#3
Thread Starter
Hyperactive Member
Thanks...
I actually found code just before you posted. It is the example for GetWindowThreadProcessId in the API-Guide from AllApi.net. Thank you very much for your help as well.
JOe
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|