Пример #1
0
        /// <summary>
        /// This pokes into a given a HwndSource and extracts the window class atom for its hwnd
        /// </summary>
        /// <param name="source"></param>
        /// <returns></returns>
        private ushort GetClassAtom(HwndSource source)
        {
            object hwndWrapper;
            Type   hwndWrapperType;

            // Grab WindowsBase and extract HwndWrapper's type
            Assembly windowsBase = Assembly.GetAssembly(typeof(DependencyObject));  // get WindowsBase

            hwndWrapperType = windowsBase.GetType("MS.Win32.HwndWrapper");

            // Get the HwndWrapper from the HwndSource
            FieldInfo hwndWrapperField = source.GetType().GetField("_hwndWrapper",
                                                                   BindingFlags.NonPublic | BindingFlags.Instance);

            hwndWrapper = hwndWrapperField.GetValue(source);

            // Extract the class atom from the hwndWrapper
            FieldInfo atomField = hwndWrapperType.GetField("_classAtom",
                                                           BindingFlags.NonPublic | BindingFlags.Instance);

            return((ushort)atomField.GetValue(hwndWrapper));
        }