Exemplo n.º 1
0
        public void RegisterClass_UnregisterActiveWindow()
        {
            WindowClass myClass = new WindowClass
            {
                ClassName       = "RegisterClass_UnregisterActiveWindow",
                WindowProcedure = CallDefaultProcedure,
            };

            Atom atom = WindowMethods.RegisterClass(ref myClass);

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

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

                try
                {
                    Action action = () => WindowMethods.UnregisterClass(atom, null);
                    action.ShouldThrow <IOException>().And
                    .HResult.Should().Be((int)ErrorMacros.HRESULT_FROM_WIN32(WindowsError.ERROR_CLASS_HAS_WINDOWS));
                }
                finally
                {
                    WindowMethods.DestroyWindow(window);
                }
            }
            finally
            {
                WindowMethods.UnregisterClass(atom, null);
            }
        }
        public void WindowCallback_SendMessage()
        {
            WindowClass myClass = new WindowClass
            {
                ClassName       = "WindowCallback_SendMessage",
                WindowProcedure = (window, message, wParam, lParam) =>
                {
                    return(42);
                }
            };

            Atom atom = WindowMethods.RegisterClass(ref myClass);

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

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

                try
                {
                    WindowMethods.SendMessage(window, WindowMessage.Activate, 0, 0).Should().Be((LRESULT)42);
                }
                finally
                {
                    WindowMethods.DestroyWindow(window);
                }
            }
            finally
            {
                WindowMethods.UnregisterClass(atom, null);
            }
        }
Exemplo n.º 3
0
        public void CreateWindow_Global()
        {
            WindowHandle window = new WindowHandle();

            try
            {
                window = WindowMethods.CreateWindow("BUTTON", "CreateWindow_Global", WindowStyles.Diabled | WindowStyles.Minimize);
                window.IsValid.Should().BeTrue();
            }
            finally
            {
                if (window.IsValid)
                {
                    WindowMethods.DestroyWindow(window);
                }
            }
        }
        public void WindowCallback_Subclass()
        {
            int         value   = 42;
            WindowClass myClass = new WindowClass
            {
                ClassName       = "WindowCallback_Subclass",
                WindowProcedure = (window, message, wParam, lParam) =>
                {
                    return(value);
                }
            };

            Atom atom = WindowMethods.RegisterClass(ref myClass);

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

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

                try
                {
                    WindowMethods.SendMessage(window, WindowMessage.Activate, 0, 0).Should().Be((LRESULT)42);

                    IntPtr          previous = IntPtr.Zero;
                    WindowProcedure subClass = (w, m, wParam, lParam) =>
                    {
                        return(WindowMethods.CallWindowProcedure(previous, w, m, wParam, lParam));
                    };

                    value    = 1999;
                    previous = WindowMethods.SetWindowProcedure(window, subClass);
                    WindowMethods.SendMessage(window, WindowMessage.Activate, 0, 0).Should().Be((LRESULT)1999);
                    GC.KeepAlive(subClass);
                }
                finally
                {
                    WindowMethods.DestroyWindow(window);
                }
            }
            finally
            {
                WindowMethods.UnregisterClass(atom, null);
            }
        }
Exemplo n.º 5
0
        public void GetClassName_Global()
        {
            WindowHandle window = new WindowHandle();

            try
            {
                window = WindowMethods.CreateWindow("button", "GetClassName_Global", WindowStyles.Diabled | WindowStyles.Minimize);
                window.IsValid.Should().BeTrue();
                WindowMethods.GetClassName(window).Should().Be("Button");
            }
            finally
            {
                if (window.IsValid)
                {
                    WindowMethods.DestroyWindow(window);
                }
            }
        }
Exemplo n.º 6
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);
            }
        }
Exemplo n.º 7
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);
                }
            }
        }