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 5 4631
I wrote the following sample to get you started:
delegate int EnumWindowsProc(IntPtr hWnd, IntPtr lParam);
[DllImport("user32.dll")]
static extern bool EnumWindows(EnumWindowsProc lpEnumFunc, IntPtr
lParam);
[DllImport("user32.dll")]
static extern int GetWindowText(IntPtr hWnd, [Out] StringBuilder
lpString, int nMaxCount);
[DllImport("user32.dll")]
static extern int GetWindowTextLength(IntPtr hWnd);
[DllImport("user32.dll")]
static extern bool IsWindowVisible(IntPtr hWnd);
private static int PrintText(IntPtr hWnd, IntPtr lParam)
{
if (IsWindowVisible(hWnd))
{
int length = GetWindowTextLength(hWnd);
StringBuilder sb = new StringBuilder(length + 1);
int res = GetWindowText(hWnd, sb, sb.Capacity);
if (res > 0)
Console.WriteLine(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
Thanks Jakob, it works. I have one more question. After I found the
application by title, I want to kill it. However, I used
TerminateProcess(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("user32.dll")] static extern bool EnumWindows(EnumWindowsProc lpEnumFunc, IntPtr lParam); [DllImport("user32.dll")] static extern int GetWindowText(IntPtr hWnd, [Out] StringBuilder lpString, int nMaxCount); [DllImport("user32.dll")] static extern int GetWindowTextLength(IntPtr hWnd); [DllImport("user32.dll")] static extern bool IsWindowVisible(IntPtr hWnd);
private static int PrintText(IntPtr hWnd, IntPtr lParam) { if (IsWindowVisible(hWnd)) { int length = GetWindowTextLength(hWnd); StringBuilder sb = new StringBuilder(length + 1); int res = GetWindowText(hWnd, sb, sb.Capacity); if (res > 0) Console.WriteLine(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
Use the Win32 API function GetWindowThreadProcessId to get the id of the
process that started your window. You can then use the managed class
System.Diagnostics.Process to kill the process using either Process.Kill or
Process.CloseMainWindow:
[DllImport("user32.dll")]
static extern uint GetWindowThreadProcessId(IntPtr hWnd, out int
lpdwProcessId);
// ...
int processId;
GetWindowThreadProcessId(hWnd, out processId);
Process proc = Process.GetProcessById(processId);
// Request a close (use Kill() to force a close)
proc.CloseMainWindow();
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 TerminateProcess(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("user32.dll")] static extern bool EnumWindows(EnumWindowsProc lpEnumFunc, IntPtr lParam); [DllImport("user32.dll")] static extern int GetWindowText(IntPtr hWnd, [Out] StringBuilder lpString, int nMaxCount); [DllImport("user32.dll")] static extern int GetWindowTextLength(IntPtr hWnd); [DllImport("user32.dll")] static extern bool IsWindowVisible(IntPtr hWnd);
private static int PrintText(IntPtr hWnd, IntPtr lParam) { if (IsWindowVisible(hWnd)) { int length = GetWindowTextLength(hWnd); StringBuilder sb = new StringBuilder(length + 1); int res = GetWindowText(hWnd, sb, sb.Capacity); if (res > 0) Console.WriteLine(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
On Thu, 29 Sep 2005 20:26:04 -0700, "Tedmond"
<Te*****@discussions.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
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*****@discussions.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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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...
|
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...
|
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;...
|
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...
|
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...
|
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)
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
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...
|
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,...
|
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...
|
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...
|
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,...
| |