473,777 Members | 1,715 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Getting titles of all openning windows process

Dear all,

How can I get all the titles of all openning windows? I found a API in
win32 that called EnumWindows() but it returns only the windows handles, not
titles. How can I get the list just like the Applications tab in Windows Task
Manager?

Thanks,

Tedmond
Sep 30 '05 #1
5 4696
I wrote the following sample to get you started:

delegate int EnumWindowsProc (IntPtr hWnd, IntPtr lParam);
[DllImport("user 32.dll")]
static extern bool EnumWindows(Enu mWindowsProc lpEnumFunc, IntPtr
lParam);
[DllImport("user 32.dll")]
static extern int GetWindowText(I ntPtr hWnd, [Out] StringBuilder
lpString, int nMaxCount);
[DllImport("user 32.dll")]
static extern int GetWindowTextLe ngth(IntPtr hWnd);
[DllImport("user 32.dll")]
static extern bool IsWindowVisible (IntPtr hWnd);

private static int PrintText(IntPt r hWnd, IntPtr lParam)
{
if (IsWindowVisibl e(hWnd))
{
int length = GetWindowTextLe ngth(hWnd);
StringBuilder sb = new StringBuilder(l ength + 1);
int res = GetWindowText(h Wnd, sb, sb.Capacity);
if (res > 0)
Console.WriteLi ne(sb.ToString( ));
}
return 1;
}

public static void Main(string[] args)
{
EnumWindowsProc cb = new EnumWindowsProc (PrintText);
EnumWindows(cb, IntPtr.Zero);
}

HTH, Jakob.

--
http://www.dotninjas.dk
http://www.powerbytes.dk
"Tedmond" wrote:
Dear all,

How can I get all the titles of all openning windows? I found a API in
win32 that called EnumWindows() but it returns only the windows handles, not
titles. How can I get the list just like the Applications tab in Windows Task
Manager?

Thanks,

Tedmond

Sep 30 '05 #2
Thanks Jakob, it works. I have one more question. After I found the
application by title, I want to kill it. However, I used
TerminateProces s(hWnd) but could not kill the window. Do you have any idea?

Thanks for any help.

Tedmond

"Jakob Christensen" wrote:
I wrote the following sample to get you started:

delegate int EnumWindowsProc (IntPtr hWnd, IntPtr lParam);
[DllImport("user 32.dll")]
static extern bool EnumWindows(Enu mWindowsProc lpEnumFunc, IntPtr
lParam);
[DllImport("user 32.dll")]
static extern int GetWindowText(I ntPtr hWnd, [Out] StringBuilder
lpString, int nMaxCount);
[DllImport("user 32.dll")]
static extern int GetWindowTextLe ngth(IntPtr hWnd);
[DllImport("user 32.dll")]
static extern bool IsWindowVisible (IntPtr hWnd);

private static int PrintText(IntPt r hWnd, IntPtr lParam)
{
if (IsWindowVisibl e(hWnd))
{
int length = GetWindowTextLe ngth(hWnd);
StringBuilder sb = new StringBuilder(l ength + 1);
int res = GetWindowText(h Wnd, sb, sb.Capacity);
if (res > 0)
Console.WriteLi ne(sb.ToString( ));
}
return 1;
}

public static void Main(string[] args)
{
EnumWindowsProc cb = new EnumWindowsProc (PrintText);
EnumWindows(cb, IntPtr.Zero);
}

HTH, Jakob.

--
http://www.dotninjas.dk
http://www.powerbytes.dk
"Tedmond" wrote:
Dear all,

How can I get all the titles of all openning windows? I found a API in
win32 that called EnumWindows() but it returns only the windows handles, not
titles. How can I get the list just like the Applications tab in Windows Task
Manager?

Thanks,

Tedmond

Sep 30 '05 #3
Use the Win32 API function GetWindowThread ProcessId to get the id of the
process that started your window. You can then use the managed class
System.Diagnost ics.Process to kill the process using either Process.Kill or
Process.CloseMa inWindow:

[DllImport("user 32.dll")]
static extern uint GetWindowThread ProcessId(IntPt r hWnd, out int
lpdwProcessId);

// ...
int processId;
GetWindowThread ProcessId(hWnd, out processId);
Process proc = Process.GetProc essById(process Id);
// Request a close (use Kill() to force a close)
proc.CloseMainW indow();

HTH, Jakob.

--
http://www.dotninjas.dk
http://www.powerbytes.dk
"Tedmond" wrote:
Thanks Jakob, it works. I have one more question. After I found the
application by title, I want to kill it. However, I used
TerminateProces s(hWnd) but could not kill the window. Do you have any idea?

Thanks for any help.

Tedmond

"Jakob Christensen" wrote:
I wrote the following sample to get you started:

delegate int EnumWindowsProc (IntPtr hWnd, IntPtr lParam);
[DllImport("user 32.dll")]
static extern bool EnumWindows(Enu mWindowsProc lpEnumFunc, IntPtr
lParam);
[DllImport("user 32.dll")]
static extern int GetWindowText(I ntPtr hWnd, [Out] StringBuilder
lpString, int nMaxCount);
[DllImport("user 32.dll")]
static extern int GetWindowTextLe ngth(IntPtr hWnd);
[DllImport("user 32.dll")]
static extern bool IsWindowVisible (IntPtr hWnd);

private static int PrintText(IntPt r hWnd, IntPtr lParam)
{
if (IsWindowVisibl e(hWnd))
{
int length = GetWindowTextLe ngth(hWnd);
StringBuilder sb = new StringBuilder(l ength + 1);
int res = GetWindowText(h Wnd, sb, sb.Capacity);
if (res > 0)
Console.WriteLi ne(sb.ToString( ));
}
return 1;
}

public static void Main(string[] args)
{
EnumWindowsProc cb = new EnumWindowsProc (PrintText);
EnumWindows(cb, IntPtr.Zero);
}

HTH, Jakob.

--
http://www.dotninjas.dk
http://www.powerbytes.dk
"Tedmond" wrote:
Dear all,

How can I get all the titles of all openning windows? I found a API in
win32 that called EnumWindows() but it returns only the windows handles, not
titles. How can I get the list just like the Applications tab in Windows Task
Manager?

Thanks,

Tedmond

Sep 30 '05 #4
On Thu, 29 Sep 2005 20:26:04 -0700, "Tedmond"
<Te*****@discus sions.microsoft .com> wrote:
Dear all,

How can I get all the titles of all openning windows? I found a API in
win32 that called EnumWindows() but it returns only the windows handles, not
titles. How can I get the list just like the Applications tab in Windows Task
Manager?

Thanks,

Tedmond


....or a much simpler approach would be to use the Process class built
into the .Net Framework.

You can enumerate all running processes, you can look at the Title
Text, and you can kill the process.

... all without using any pinvoke to APIs!

http://msdn.microsoft.com/library/de...classtopic.asp
Oct 2 '05 #5
That would give you all running processes - not just the ones with a visible
Window.

Regards, Jakob.
--
http://www.dotninjas.dk
http://www.powerbytes.dk
"Emmet Gray" wrote:
On Thu, 29 Sep 2005 20:26:04 -0700, "Tedmond"
<Te*****@discus sions.microsoft .com> wrote:
Dear all,

How can I get all the titles of all openning windows? I found a API in
win32 that called EnumWindows() but it returns only the windows handles, not
titles. How can I get the list just like the Applications tab in Windows Task
Manager?

Thanks,

Tedmond


....or a much simpler approach would be to use the Process class built
into the .Net Framework.

You can enumerate all running processes, you can look at the Title
Text, and you can kill the process.

... all without using any pinvoke to APIs!

http://msdn.microsoft.com/library/de...classtopic.asp

Oct 3 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
5670
by: Ohad Young | last post by:
Hi, I need to open (launch) an external application from my winform application. The application is not a dot.net application, for example the windows calculator. I'm using the System.Diagnostics.Process class, for example: .... System.Diagnostics.Process proc = new System.Diagnostics.Process(); proc.EnableRaisingEvents = false;
8
10016
by: Rod | last post by:
I have been working with ASP.NET 1.1 for quite a while now. For some reason, opening some ASP.NET applications we wrote is producing the following error message: "The Web server reported the following error when attempting to create or open the Web project located at the following URL: 'http://localhost/WebApplication1'. 'HTTP/1.1 500 Internal Server Error'."
2
2388
by: Henrik | last post by:
Hi all, I'm working with a win app in vb that needs access to actual process id of the office-applications Word, Excel and PowerPoint. I know I can loop the processes and check for processes of these applications by name etc., but it will not be good enough, I need to use the exact process id. I also know that I can get it for Excel by doing as described here:...
5
332
by: Tedmond | last post by:
Dear all, How can I get all the titles of all openning windows? I found a API in win32 that called EnumWindows() but it returns only the windows handles, not titles. How can I get the list just like the Applications tab in Windows Task Manager? Thanks, Tedmond
0
476
by: Sally Whitfield | last post by:
8Zcc ----uMyItidGBFcIxNvn7Ubo Content-Type: text/html; Content-Transfer-Encoding: quoted-printable <html><head><style type=3Dtext/css>.eyebrow { FONT-WEIGHT: bold; FONT-SIZE= : 10px; TEXT-TRANSFORM: uppercase; COLOR: #ffffff; FONT-FAMILY: verdana,ar= ial,helvetica,sans-serif; TEXT-DECORATION: none } A.eyebrow:link { TEXT-DE= CORATION: none }</style><title>W</title><meta http-equiv=3DContent-Type co=
2
4222
by: MSK | last post by:
Hi, Continued to my earlier post regaring "Breakpoints are not getting hit" , I have comeup with more input this time.. Kindly give me some idea. I am a newbie to .NET, recently I installed .NET. I could not debug using breakpoints, breakpoints are not getting hit, but the application is working fine with out any issue.
1
1273
by: Pankajmani das | last post by:
I have developed a program which is need to run automatically when windows/computer start. I have kept my exe file in startup and task folder manually and it work also. Please let me know the code for doing all this things, and if another process is there.
0
936
by: Tobias Maier | last post by:
hello I can't retrieve the windows captions / -titles from processes on Windows Server 2003. On Windows XP all works fine. I use the following: - win32 api FindWindow (by title)
20
35543
by: TomLasky | last post by:
Hi everyone, I ran into a road block and cant seem to find anything on google. I need to check all open windows/processes to see if certain software is running on the system. I was going to go the route of using core api from user32 for findwindow and so on, but then I came across using Process.Getprocesses and was very happy to see it was easy to get all processes and MainWindowTitle Dim poc() As Process = Process.GetProcesses() ...
0
9464
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10122
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10061
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9923
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8954
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7471
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5497
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3627
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2860
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.