public void WindowCallback_SendMessage() { WindowClassInfo myClass = new WindowClassInfo { ClassName = "WindowCallback_SendMessage", WindowProcedure = (window, message, wParam, lParam) => { return(42); } }; Atom atom = Windows.RegisterClass(ref myClass); atom.IsValid.Should().BeTrue(); try { WindowHandle window = Windows.CreateWindow(atom, style: WindowStyles.Minimize | WindowStyles.Diabled); window.IsInvalid.Should().BeFalse(); try { window.SendMessage(MessageType.Activate).Should().Be((LResult)42); } finally { window.DestroyWindow(); } } finally { Windows.UnregisterClass(atom); } }
public void GetClassLong_GlobalAtom() { WindowHandle window = new WindowHandle(); try { window = Windows.CreateWindow("bUttOn", "GetClassLong_GlobalAtom", WindowStyles.Diabled | WindowStyles.Minimize); window.IsInvalid.Should().BeFalse(); Atom atom = window.GetClassLong(ClassLong.Atom); atom.IsValid.Should().BeTrue(); window.DestroyWindow(); window = Windows.CreateWindow(atom, "GetClassLong_GlobalAtom", WindowStyles.Diabled | WindowStyles.Minimize); window.GetClassName().Should().Be("Button"); } finally { if (!window.IsInvalid) { window.DestroyWindow(); } } }
public void CreateWindow_Global() { WindowHandle window = default; try { window = Windows.CreateWindow("BUTTON", "CreateWindow_Global", WindowStyles.Diabled | WindowStyles.Minimize); window.IsInvalid.Should().BeFalse(); } finally { if (!window.IsInvalid) { window.DestroyWindow(); } } }
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 WindowClassInfo myClass = new WindowClassInfo { ClassName = "RegisterClass_GetSetClassLong", Style = ClassStyle.HorizontalRedraw, WindowProcedure = CallDefaultProcedure, ClassExtraBytes = 80 }; Atom atom = Windows.RegisterClass(ref myClass); atom.IsValid.Should().BeTrue(); try { WindowHandle window = Windows.CreateWindow( atom, "RegisterClass_GetSetClassLong_Window", WindowStyles.Diabled | WindowStyles.Minimize); window.IsInvalid.Should().BeFalse(); try { var info = Windows.GetClassInfo(Modules.GetModuleHandle(null), atom); info.ClassExtraBytes.Should().Be(80); IntPtr result = Windows.SetClassLong(window, (ClassLong)72, (IntPtr)0x0000BEEF); result.Should().Be(IntPtr.Zero); window.GetClassLong((ClassLong)72).Should().Be((IntPtr)0x0000BEEF); } finally { window.DestroyWindow(); } } finally { Windows.UnregisterClass(atom, null); } }
public void GetClassName_Global() { WindowHandle window = default; try { window = Windows.CreateWindow("button", "GetClassName_Global", WindowStyles.Diabled | WindowStyles.Minimize); window.IsInvalid.Should().BeFalse(); window.GetClassName().Should().Be("Button"); } finally { if (!window.IsInvalid) { window.DestroyWindow(); } } }
public void RegisterClass_UnregisterActiveWindow() { WindowClassInfo myClass = new WindowClassInfo { ClassName = "RegisterClass_UnregisterActiveWindow", WindowProcedure = CallDefaultProcedure, }; Atom atom = Windows.RegisterClass(ref myClass); atom.IsValid.Should().BeTrue(); try { WindowHandle window = Windows.CreateWindow( atom, "RegisterClass_UnregisterActiveWindow", WindowStyles.Diabled | WindowStyles.Minimize); window.IsInvalid.Should().BeFalse(); try { Action action = () => Windows.UnregisterClass(atom, null); action.Should().Throw <IOException>().And .HResult.Should().Be((int)WindowsError.ERROR_CLASS_HAS_WINDOWS.ToHResult()); } finally { window.DestroyWindow(); } } finally { Windows.UnregisterClass(atom, null); } }