Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how can I get Hwnd FROM PID?

Status
Not open for further replies.

yesterdayze

Programmer
Mar 12, 2003
1
0
0
US
I need to be able to retrieve the Handle of a window, not the handle of the thread (IE not what OpenProcess(PROCESS_QUERY_INFORMATION Or PROCESS_VM_READ, 0, ProcessID) would return) in a Visual Basic 6 program.


Any ideas on doing this? I am not adverse to a loop, but would prefer a better way. If not though could you help with a loop, I tried but cannot seem to retrieve any of the windows below the desktop. Thanks :)
 
In the User Interface section of the Windows Platform SDK you will find the function GetWindowThreadProcessId

hope that helps
-pete
 
Maybe first you start by identify your target process, then
Enumerate the windows from the system and check one by one using GetWindowThreadProcessId(current_hwnd, ) if is the one you need (i.e. has same process id )

or use EnumThreadWindows and obtain all windows on target process....

e.g a sample pseudocode (sorry 'cause it looks like C ):

for each current_hwnd in sistem //here use EnumWindows
{
DWORD dwCrt_id;
GetWindowThreadProcessId(current_hwnd, &dwCrt_id);
if(dwCrt_id == my_targetid)
{
...
dosomething (current_hwnd);
...
}

}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top