Windows Handle -> IProcess.Handle

delphi package - easy access to kernel objects etc.
Post Reply
Jeff_Lawton
Posts: 7
Joined: Tue Jul 20, 2004 8:20 pm
Location: Sacramento, CA
Contact:

Windows Handle -> IProcess.Handle

Post by Jeff_Lawton »

Is there a way to get a IProcess from a windows Handle?

I can only find things like

MadKernel.Window(hWnd).OwnerProcess;

Is that the window I am looking at or the Owner of that window.. I am looking for the IProcess for the window matching the hWnd.

Any way to get that? I am willing to bet I missed something..

Thanks

Jeff Lawton
madshi
Site Admin
Posts: 10764
Joined: Sun Mar 21, 2004 5:25 pm

Re: Windows Handle -> IProcess.Handle

Post by madshi »

Jeff_Lawton wrote:Is there a way to get a IProcess from a windows Handle?
I can only find things like
MadKernel.Window(hWnd).OwnerProcess;
That's exactly the solution.
Jeff_Lawton
Posts: 7
Joined: Tue Jul 20, 2004 8:20 pm
Location: Sacramento, CA
Contact:

Re: Windows Handle -> IProcess.Handle

Post by Jeff_Lawton »

madshi wrote:
Jeff_Lawton wrote:Is there a way to get a IProcess from a windows Handle?
I can only find things like
MadKernel.Window(hWnd).OwnerProcess;
That's exactly the solution.
What about doing the reverse? Lets say I wanted a windows handle from an IProcess so I could do something like :

SetForegroundWindow(hWnd);

I have tried stuff like - Process.Handle.Handle, but this doesn't seem to give the correct windows handle.

Thanks for the help.

Jeff Lawton
madshi
Site Admin
Posts: 10764
Joined: Sun Mar 21, 2004 5:25 pm

Post by madshi »

"IProcess.Handle" gives you a process handle, what else did you expect? The name already sais it, it's a handle of the IProcess.

You need to understand that each process can have none, one or a multitude of windows. There is not "the one" window of a process. There never was. Well, in real life most processes do have only one main window. But this is just a design decision, Windows doesn't force a specific main window count per process.

If you are looking for the main window(s) of a process, you should first of all loop through IProcess.TaskbarWindows. These are windows which are shown in the taskbar. Most processes have one there or none. Some few processes may have more than one there. The process with no "taskbar windows" might have "main" windows which are not listed in the taskbar instead. You'll need to loop through IProcess.Windows_ to find those.
Post Reply