Hey,
I was just wondering if .NET provided any routines that can enumerate open windows. I know it can be done using some windows API calls, but I wasn't sure if .NET had any such features. Thanks in advance for any help.
Hey,
I was just wondering if .NET provided any routines that can enumerate open windows. I know it can be done using some windows API calls, but I wasn't sure if .NET had any such features. Thanks in advance for any help.
Does .Net provide any routines to list open windows?
Bruce VB
Surya Suluh
Thanks jelle, I'm learning while answering
I tried your approach and can't make it show all the windows in my System; My bad, I haven't checked the documentation, it says, it's only to enumerate Windows owned by Application, not all windows:
http://msdn2.microsoft.com/en-us/library/system.windows.forms.application.openforms.aspx
Ok, I still used API calls to enumerate windows (I attached it to button1_Click event):
private delegate bool EnumWindowsCallBack(IntPtr hwnd, IntPtr lparam);
[DllImport("user32.dll", CharSet=CharSet.Auto)]
private static extern bool EnumWindows(EnumWindowsCallBack callback, IntPtr lparam);
[DllImport("user32.dll", CharSet=CharSet.Auto)]
private static extern int GetWindowText(IntPtr hwnd, StringBuilder lpString, int cch);
private void button1_Click(object sender, System.EventArgs e)
{
EnumWindowsCallBack enumwinproc = new EnumWindowsCallBack(EnumarateWindows);
EnumWindows(enumwinproc, IntPtr.Zero);
GC.KeepAlive(enumwinproc);
}
private bool EnumarateWindows(IntPtr hwnd, IntPtr lparam)
{
StringBuilder sbWindowText = new StringBuilder(1024);
GetWindowText(hwnd, sbWindowText, 1024);
MessageBox.Show(hwnd.ToInt32().ToString("X") + ": Text = " + sbWindowText.ToString());
return true;
}
Once you've clicked the button, it will display all top-level windows
Hope this helps,
-chris
Embedded Developer
Anyway, EnumWindows and/or FindWindow API are fairly easy to implement in .NET.
Regards,
-chris