开发者

Collect all windows handlers

开发者 https://www.devze.com 2022-12-18 10:09 出处:网络
How do I collect all windows handlers i开发者_JAVA百科n C#. I need all the windows (not just the parents)

How do I collect all windows handlers i开发者_JAVA百科n C#. I need all the windows (not just the parents) Thanks,


Try the following utility class. Given a handle to a window it will return all of the associated child windows.

public class WindowFinder
{
    private class Helper
    {

        internal List<IntPtr> Windows = new List<IntPtr>();

        internal bool ProcessWindow(IntPtr handle, IntPtr parameter)
        {
            Windows.Add(handle);
            return true;
        }
    }

    private delegate bool EnumWindowProc(IntPtr hWnd, IntPtr parameter);

    [DllImport("user32.dll")]
    [return: MarshalAs(UnmanagedType.Bool)]
    private static extern bool EnumChildWindows(IntPtr hwndParent, EnumWindowProc lpEnumFunc, IntPtr lParam);

    public static List<IntPtr> GetChildWindows(IntPtr parentWindow)
    {
        var helper = new Helper();
        EnumChildWindows(parentWindow, helper.ProcessWindow, IntPtr.Zero);
        return helper.Windows;
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消