473,396 Members | 2,147 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,396 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 7109
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.