468,768 Members | 1,705 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,768 developers. It's quick & easy.

How to find hWnd handle from enumerated process?

Hi i need to work with windows of processes that are running on my pc
from a certain programme. I've figured out how to build an array of
processes that contain just the processes i'm interested in by checking
what the process name starts with.

How do i find out the hWnd for the processes i've returned, because the
function i need to run wants me to pass it the hWnd of the processes.

Here's what I have so far, using notepad as my example : -

static void EnumerateWindows()
{
System.Diagnostics.Process[] processes;
processes =
System.Diagnostics.Process.GetProcessesByName("not epad");

foreach (System.Diagnostics.Process instance in processes)
{
MessageBox.Show(instance.Handle.ToString());

}

}
}

Thankyou experts,

Gary.

Jan 14 '07 #1
2 6885
Gary wrote:
How do i find out the hWnd for the processes i've returned, because the
function i need to run wants me to pass it the hWnd of the processes.
static void EnumerateWindows()
MessageBox.Show(instance.Handle.ToString());
What you've got there is a HINSTANCE, not a HWND.

One way of doing it:
- use P/Invoke and call EnumWindows, passing in a callback.
- then use P/Invoke and call GetWindowThreadProcessId to get the PID
- you can then use the PID with Process.GetProcessById to do your
filtering.

http://pinvoke.net has some info on prototypes to use for EnumWindows()
and friends.

-- Barry

--
http://barrkel.blogspot.com/
Jan 14 '07 #2
Barry Kelly wrote:
What you've got there is a HINSTANCE, not a HWND.
Whups - I mis-remembered. It's a handle to the process, but that doesn't
materially change my suggestion.

-- Barry

--
http://barrkel.blogspot.com/
Jan 14 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Abhishek | last post: by
4 posts views Thread by Nayan | last post: by
2 posts views Thread by Gary | last post: by
15 posts views Thread by =?Utf-8?B?Sm9hY2hpbQ==?= | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by Marin | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.