No.
A process can have multiple windows open.
You could however iterate over all the windows and retrieve the process ID from the HWND and match this process ID with the ID you are interested in. Check out GetWindowThreadProcessId .
HWND h = ::GetTopWindow(0 );
while ( h )
{
DWORD pid;
DWORD dwTheardId = ::GetWindowThreadProcessId( h,&pid);
if ( pid == /*your process id*/ )
{
// here h is the handle to the window
break;
}
h = ::GetNextWindow( h , GW_HWNDNEXT);
}
Cheers
If a post helped you dont forget to "Rate This Post"
Sample Code is working Fine. I can able to get the Handles of all open windows. Still I have a doubt what is handle (HANDLE) and what is handle to window ( HWND ) is there any difference in that.
Please clarify my doubt, if possible give a good direction to know more about it.
A HWND is a special type of a HANDLE: a handle to a window. Likewise HFILE is a handle to a file. Since some functions work with more than one type of handle there is the generic type HANDLE. For example with CloseHandle() you can close a file handle or a thread handle, etc. A handle is only a kind of pointer to the real thing, which is managed internly by windows.
A HWND is a special type of a HANDLE: a handle to a window. Likewise HFILE is a handle to a file. Since some functions work with more than one type of handle there is the generic type HANDLE. For example with CloseHandle() you can close a file handle or a thread handle, etc. A handle is only a kind of pointer to the real thing, which is managed internly by windows.
A HWND is not HANDLE but it is a handle indeed. A HWND cannot be used to replace when a HANDLE is needed. And HFILE shall not be used anymore, it got generally replaced via HANDLE and it's only served through backward compatibility with 16bit windows and the "old" I/O routines.
E:\Temp\558>cl 558.cpp
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 13.10.3077 for 80x86
Copyright (C) Microsoft Corporation 1984-2002. All rights reserved.
558.cpp
558.cpp(8) : error C2440: '=' : cannot convert from 'HANDLE' to 'HWND'
Conversion from 'void*' to pointer to non-'void' requires an explicit cast
Bookmarks