How to get A WindowHandle from a process Id
-
Can anybody tell how I get the window handle from a specific process Id. I got the process Id using GetCurrentProcessId()
Regards Rajmohan
-
Can anybody tell how I get the window handle from a specific process Id. I got the process Id using GetCurrentProcessId()
Regards Rajmohan
Which window handle? There are usually more windows belonging to a process (e.g. controls on a dialog like buttons, edit fields have a window handle too). Anyways, i assume you are looking for a top level popup window, one method would be to enumerate all the windows, for example using EnumWindows[^], on every window you could call GetWindowThreadProcessId[^] to get the id of the process the window belongs to and test for equality...
> The problem with computers is that they do what you tell them to do and not what you want them to do. < > Sometimes you just have to hate coding to do it well. <
-
Can anybody tell how I get the window handle from a specific process Id. I got the process Id using GetCurrentProcessId()
Regards Rajmohan
The handle of what window? To retrieve all windows of a process, you have to call EnumWindows and, for each window, use GetWindowThreadProcessId to check if a window belongs to a process (the ProcessID of the window equals the ProcessID of the process).
-
Can anybody tell how I get the window handle from a specific process Id. I got the process Id using GetCurrentProcessId()
Regards Rajmohan
-
Can anybody tell how I get the window handle from a specific process Id. I got the process Id using GetCurrentProcessId()
Regards Rajmohan
See here [^]. :)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
Can anybody tell how I get the window handle from a specific process Id. I got the process Id using GetCurrentProcessId()
Regards Rajmohan
There is no single window handle. A process may have multiple main windows, or none at all. So you have to enumerate all windows, and select the ones which have no owner, and the correct process id. Those will be 'main' windows of the process. And before thou protests: Yes, I know that in .Net there is a property called System.Diagnostics.Process.MainWindowHandle, but the implementation is just plain wrong.
-
Can anybody tell how I get the window handle from a specific process Id. I got the process Id using GetCurrentProcessId()
Regards Rajmohan
Thank you so much for all the support. I forget to mention the Window Handle,It is of-course the parent window itself
Regards Rajmohan
-
The handle of what window? To retrieve all windows of a process, you have to call EnumWindows and, for each window, use GetWindowThreadProcessId to check if a window belongs to a process (the ProcessID of the window equals the ProcessID of the process).
EnumWindows function is working fine with all windows except my application. I will describe the issue in detail. I have a dll application and I have loaded it into App_Init folder, which loads for every application. I want to know which is currently loaded application and also I need to get the handle of the main window. I used EnumWindows for navigating through opened application. It is calling for all the application except mine. I dont understand the issue can anybody help me. Thanks in advance
Regards Rajmohan
-
Can anybody tell how I get the window handle from a specific process Id. I got the process Id using GetCurrentProcessId()
Regards Rajmohan
EnumWindows function is working fine with all windows except my application. I will describe the issue in detail. I have a dll application and I have loaded it into App_Init folder, which loads for every application. I want to know which is currently loaded application and also I need to get the handle of the main window. I used EnumWindows for navigating through opened application. It is calling for all the application except mine. I dont understand the issue can anybody help me. Thanks in advance
Regards Rajmohan