Joey_k29
Jan 10th, 2002, 09:56 AM
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
crispin
Jan 10th, 2002, 10:48 AM
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
Joey_k29
Jan 10th, 2002, 11:05 AM
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