Question

Comment puis-je collectionne tous les gestionnaires de fenêtres en C #. Je besoin de toutes les fenêtres (pas seulement des parents) Merci,

Était-ce utile?

La solution

Essayez la classe utilitaire suivant. Compte tenu d'une poignée à une fenêtre, il retournera toutes les fenêtres enfants associés.

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;
    }
}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top