473,327 Members | 2,025 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 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 7100
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...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.