I need a functionality that enumerates through open explorer windows. And here is a code I’ve got:
delegate bool EnumThreadDelegate(IntPtr hWnd, IntPtr lParam);
[DllImport("user32.dll")]
static extern bool EnumThreadWindows(int dwThreadId, EnumThreadDelegate lpfn, IntPtr lParam);
static IEnumerable<IntPtr> EnumerateProcessWindowHandles(int processID)
{
List<IntPtr> handles = new List<IntPtr>();
foreach (ProcessThread thread in Process.GetProcessById(processID).Threads)
{ //what is the magic going on beneath this?? :o
EnumThreadWindows(thread.Id, (hWnd, lParam) => { handles.Add(hWnd); return true;}, IntPtr.Zero);
}
return handles;
}
And the code continues here like this:
[DllImport("coredll.dll")]
static extern int ShowWindow(IntPtr hWnd, int nCmdShow);
const int SW_MINIMIZED = 6;
private void button1_Click(object sender, EventArgs e)
{
foreach (IntPtr handle in EnumerateProcessWindowHandles(Process.GetProcessesByName("explorer")[0].Id))
{
ShowWindow(handle, SW_MINIMIZED);
}
}
My question is, in the first block of code, how do I replace the lambda expression so that I can compile the code using C# 2.0 in VS 2005.
1 Answer