472,958 Members | 2,592 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,958 software developers and data experts.

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 7074
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: John Regan | last post by:
Hello All I am trying to find the owner of a file or folder on our network (Windows 2000 Server) using VB.Net and/or API. so I can search for Folders that don't follow our company's specified...
5
by: MrBewsher | last post by:
Hi, I'm using VB.Net and writing an NT service that runs in the system account in the background with no interaction with the desktop. I'm running it on XP Pro. I'd like to get the URL of...
4
by: Shawnk | last post by:
This post is intended to verify that true value semantics DO NOT EXIST for the Enum class (relative to boolean operations). If this is true then (thus and therefore) you can not design state...
3
by: Abhishek | last post by:
Hi, how do you convert HWND to HMODULE or if you have the HWND how do u get its HMODULE. regards Abhishek
4
by: Nayan | last post by:
The base process owns this thread. But the visible window is owned by the thread. How do I get the owner Process ID from a Thread ID? To understand, look at this "<<--" pointer in the...
0
by: kloplop321 | last post by:
I found this code(vb only) and it does about the same thing(in vb, not vb .NET 2005) Attribute VB_Name = "Form1" Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False Attribute...
0
by: Gary | last post by:
static void EnumerateWindows() { ArrayList daprocesses = new ArrayList(); System.Diagnostics.Process processes; processes = System.Diagnostics.Process.GetProcessesByName("Darkages"); ...
2
by: Gary | last post by:
static void EnumerateWindows() { ArrayList daprocesses = new ArrayList(); System.Diagnostics.Process processes; processes = System.Diagnostics.Process.GetProcessesByName("Darkages"); ...
15
by: =?Utf-8?B?Sm9hY2hpbQ==?= | last post by:
How can I pass a C++ HWND to and from C# and Managed C++?
10
by: Gary | last post by:
I'm trying to find a way to determin which window Within-Another-Program currently has the focus. THE SITUATION: (Skip down to "My Question" if you don't want the background...) * This is...
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
2
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.