コード例 #1
0
        private static Icon GetWindowIcon(IntPtr handle)
        {
            if (MessagingMethods.SendMessageTimeout(
                    handle,
                    Wm.Geticon,
                    new IntPtr(0),
                    new IntPtr(0),
                    MessagingMethods.SendMessageTimeoutFlags.AbortIfHung | MessagingMethods.SendMessageTimeoutFlags.Block,
                    500,
                    out var hIcon) ==
                IntPtr.Zero)
            {
                hIcon = IntPtr.Zero;
            }

            Icon result = null;

            if (hIcon != IntPtr.Zero)
            {
                result = Icon.FromHandle(hIcon);
            }
            else
            {
                //Fetch icon from window class
                hIcon = WindowMethods.GetClassLong(handle, WindowMethods.ClassLong.Icon);

                if (hIcon.ToInt64() != 0)
                {
                    result = Icon.FromHandle(hIcon);
                }
            }

            return(result);
        }
コード例 #2
0
        public void RegisterClass_GetSetClassLong()
        {
            // Some docs claim that 40 is the max, but that isn't true (at least in recent OSes)
            // https://msdn.microsoft.com/en-us/library/windows/desktop/ms633574.aspx
            WindowClass myClass = new WindowClass
            {
                ClassName       = "RegisterClass_GetSetClassLong",
                Style           = ClassStyle.HorizontalRedraw,
                WindowProcedure = CallDefaultProcedure,
                ClassExtraBytes = 80
            };

            Atom atom = WindowMethods.RegisterClass(ref myClass);

            atom.IsValid.Should().BeTrue();

            try
            {
                WindowHandle window = WindowMethods.CreateWindow(atom,
                                                                 "RegisterClass_GetSetClassLong_Window", WindowStyles.Diabled | WindowStyles.Minimize);
                window.IsValid.Should().BeTrue();

                try
                {
                    var info = WindowMethods.GetClassInfo(ModuleMethods.GetModuleHandle(null), atom);
                    info.ClassExtraBytes.Should().Be(80);

                    IntPtr result = WindowMethods.SetClassLong(window, (ClassLong)72, (IntPtr)0x0000BEEF);
                    result.Should().Be(IntPtr.Zero);

                    WindowMethods.GetClassLong(window, (ClassLong)72).Should().Be((IntPtr)0x0000BEEF);
                }
                finally
                {
                    WindowMethods.DestroyWindow(window);
                }
            }
            finally
            {
                WindowMethods.UnregisterClass(atom, null);
            }
        }
コード例 #3
0
        public void GetClassLong_GlobalAtom()
        {
            WindowHandle window = new WindowHandle();

            try
            {
                window = WindowMethods.CreateWindow("bUttOn", "GetClassLong_GlobalAtom", WindowStyles.Diabled | WindowStyles.Minimize);
                window.IsValid.Should().BeTrue();
                Atom atom = WindowMethods.GetClassLong(window, ClassLong.Atom);
                atom.IsValid.Should().BeTrue();
                WindowMethods.DestroyWindow(window);
                window = WindowMethods.CreateWindow(atom, "GetClassLong_GlobalAtom", WindowStyles.Diabled | WindowStyles.Minimize);
                WindowMethods.GetClassName(window).Should().Be("Button");
            }
            finally
            {
                if (window.IsValid)
                {
                    WindowMethods.DestroyWindow(window);
                }
            }
        }