Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Get window handle from PROCESS_INFORMATION

237 views
Skip to first unread message

Mong

unread,
Jul 1, 2003, 3:23:53 AM7/1/03
to
Hi,

I'm starting an application using CreateProcess which gives me
hProcess, hThread, dwProcessID and dwThreadID. But how do I use these
to get the window handle so I can use other API calls such as
SetForegroundWindow which takes the window handle as an argument?

Thanks for any help,

Mong

J French

unread,
Jul 1, 2003, 4:32:57 AM7/1/03
to

Strangely there does not seem to be the opposite of
GetWindowThreadProcessId

Here is something that runs through topmost Windows and locates the
one with the same process ID
- not my code
- if you are using CreateProcess then you'll follow this


' --- This gives a hWnd from a Process ID
Function InstanceToWnd(ByVal target_pid As Long) As Long
Dim test_hwnd As Long, test_pid As Long, test_thread_id As Long
'Find the first window
test_hwnd = FindWindow(ByVal 0&, ByVal 0&)
Do 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
Exit Do
End If
End If
'retrieve the next window
test_hwnd = GetWindow(test_hwnd, GW_HWNDNEXT)
Loop
End Function

0 new messages