public void FindWindows_SkipsWindowsWhereGetClassNameReturnsZero() { var windowHandle1 = new IntPtr(100); var windowHandle2 = new IntPtr(200); var windowHandle3 = new IntPtr(300); NativeMethodsStub.Stub(stub => stub.EnumWindows(Arg <EnumWindowsProc> .Is.NotNull, Arg <WindowFinderEnumWindowsProcContext> .Is.NotNull)) .WhenCalled( mi => { Assert.That(InvokeEnumWindowsProc(mi, windowHandle1), Is.True); Assert.That(InvokeEnumWindowsProc(mi, windowHandle2), Is.True); Assert.That(InvokeEnumWindowsProc(mi, windowHandle3), Is.True); }) .Return(true); StubNativeMethodsForWindowInformation(NativeMethodsStub, windowHandle1, 101, "Class1", "Window1"); StubNativeMethodsForWindowInformation(NativeMethodsStub, windowHandle2, 201, "", "Window2"); StubNativeMethodsForWindowInformation(NativeMethodsStub, windowHandle3, 301, "Class3", "Window3"); var windows = WindowFinder.FindWindows(new WindowFilterCriteria()); Assert.That(windows.Length, Is.EqualTo(2)); AssertWindowInformation(windows[0], windowHandle1, 101, "Class1", "Window1"); AssertWindowInformation(windows[1], windowHandle3, 301, "Class3", "Window3"); }
public void FindWindows_IncludesChildWindowsWhereGetWindowTextReturnsZero() { var windowHandle1 = new IntPtr(100); var subWindowHandle11 = new IntPtr(1001); var subWindowHandle12 = new IntPtr(1002); NativeMethodsStub.Stub(stub => stub.EnumWindows(Arg <EnumWindowsProc> .Is.NotNull, Arg <WindowFinderEnumWindowsProcContext> .Is.NotNull)) .WhenCalled(mi => Assert.That(InvokeEnumWindowsProc(mi, windowHandle1), Is.True)) .Return(true); NativeMethodsStub.Stub( stub => stub.EnumChildWindows( Arg.Is(windowHandle1), Arg <EnumChildWindowsProc> .Is.NotNull, Arg <WindowFinderEnumChildWindowsProcContext> .Is.NotNull)) .WhenCalled( mi => { Assert.That(InvokeEnumChildWindowsProc(mi, subWindowHandle11), Is.True); Assert.That(InvokeEnumChildWindowsProc(mi, subWindowHandle12), Is.True); }); StubNativeMethodsForWindowInformation(NativeMethodsStub, windowHandle1, 101, "Class1", "Window1"); StubNativeMethodsForWindowInformation(NativeMethodsStub, subWindowHandle11, 101, "Class1.1", ""); StubNativeMethodsForWindowInformation(NativeMethodsStub, subWindowHandle12, 101, "Class1.2", "Window1.2"); var windows = WindowFinder.FindWindows(new WindowFilterCriteria { IncludeChildWindows = true }); Assert.That(windows.Length, Is.EqualTo(3)); AssertWindowInformation(windows[0], windowHandle1, 101, "Class1", "Window1"); AssertChildWindowInformation(windows[1], subWindowHandle11, 101, "Class1.1", "", windowHandle1); AssertChildWindowInformation(windows[2], subWindowHandle12, 101, "Class1.2", "Window1.2", windowHandle1); }
public void FindWindows_FilterByProcessID() { var windowHandle1 = new IntPtr(100); var windowHandle2 = new IntPtr(200); var windowHandle3 = new IntPtr(300); var windowHandle4 = new IntPtr(400); NativeMethodsStub.Stub(stub => stub.EnumWindows(Arg <EnumWindowsProc> .Is.NotNull, Arg <WindowFinderEnumWindowsProcContext> .Is.NotNull)) .WhenCalled( mi => { Assert.That(InvokeEnumWindowsProc(mi, windowHandle1), Is.True); Assert.That(InvokeEnumWindowsProc(mi, windowHandle2), Is.True); Assert.That(InvokeEnumWindowsProc(mi, windowHandle3), Is.True); Assert.That(InvokeEnumWindowsProc(mi, windowHandle4), Is.True); }) .Return(true); StubNativeMethodsForWindowInformation(NativeMethodsStub, windowHandle1, 101, "Class1", "Window1"); StubNativeMethodsForWindowInformation(NativeMethodsStub, windowHandle2, CurrentProcessID, "Class2", "Window2"); StubNativeMethodsForWindowInformation(NativeMethodsStub, windowHandle3, 101, "Class3", "Window3"); StubNativeMethodsForWindowInformation(NativeMethodsStub, windowHandle4, 401, "Class4", "Window4"); var windows = WindowFinder.FindWindows(new WindowFilterCriteria { ProcessID = 101 }); Assert.That(windows.Length, Is.EqualTo(2)); AssertWindowInformation(windows[0], windowHandle1, 101, "Class1", "Window1"); AssertWindowInformation(windows[1], windowHandle3, 101, "Class3", "Window3"); }
public void FindWindows_HandlesEnumWindowsReturnedFalse() { NativeMethodsStub.Stub(stub => stub.EnumWindows(null, null)) .IgnoreArguments() .WhenCalled(mi => NativeMethodsStub.Stub(stub => stub.GetLastWin32Error()).Return(-1).Repeat.Once()) .Return(false); WindowFinder.FindWindows(new WindowFilterCriteria()); }
public static void Maximize() { #if UNITY_EDITOR || !UNITY_STANDALONE_WIN return; #endif Task.Run(() => { var wf = new WindowFinder(); wf.FindWindows(0, null, new Regex(APP_NAME), new Regex(APP_NAME), new WindowFinder.FoundWindowCallback(MaximizeWindow)); }); }
// [RuntimeInitializeOnLoadMethod] // No need to run it on this project // private static void MaximizeWindowOnStart() // { // if (Application.isEditor) { return; } // WindowFinder wf = new WindowFinder(); // // Maxime all windows that contains "APP_NAME" in their title. // wf.FindWindows(0, null, new Regex("The Colour of Music"), new Regex("The Colour of Music"), new WindowFinder.FoundWindowCallback(MaximizeWindow)); // } public static void MaximizeWindow() { if (Application.isEditor) { return; } WindowFinder wf = new WindowFinder(); // Maxime all windows that contains "APP_NAME" in their title. wf.FindWindows(0, null, new Regex("The Colour of Music"), new Regex("The Colour of Music"), new WindowFinder.FoundWindowCallback(MaximizeWindow)); }
public void FindWindows_IncludeChildWindows_MatchesParentAndChild() { var windowHandle1 = new IntPtr(100); var windowHandle2 = new IntPtr(200); var subWindowHandle11 = new IntPtr(1001); var subWindowHandle12 = new IntPtr(1002); var subWindowHandle21 = new IntPtr(2001); NativeMethodsStub.Stub(stub => stub.EnumWindows(Arg <EnumWindowsProc> .Is.NotNull, Arg <WindowFinderEnumWindowsProcContext> .Is.NotNull)) .WhenCalled( mi => { Assert.That(InvokeEnumWindowsProc(mi, windowHandle1), Is.True); Assert.That(InvokeEnumWindowsProc(mi, windowHandle2), Is.True); }) .Return(true); NativeMethodsStub.Stub( stub => stub.EnumChildWindows( Arg.Is(windowHandle1), Arg <EnumChildWindowsProc> .Is.NotNull, Arg <WindowFinderEnumChildWindowsProcContext> .Is.NotNull)) .WhenCalled( mi => { Assert.That(InvokeEnumChildWindowsProc(mi, subWindowHandle11), Is.True); Assert.That(InvokeEnumChildWindowsProc(mi, subWindowHandle12), Is.True); Assert.That(InvokeEnumChildWindowsProc(mi, subWindowHandle21), Is.True); }); StubNativeMethodsForWindowInformation(NativeMethodsStub, windowHandle1, 101, "Class1", "Window1"); StubNativeMethodsForWindowInformation(NativeMethodsStub, windowHandle2, 201, "Class2", "Window2"); StubNativeMethodsForWindowInformation(NativeMethodsStub, subWindowHandle11, 101, "Class1.1", "Window1.1"); StubNativeMethodsForWindowInformation(NativeMethodsStub, subWindowHandle12, 101, "Class1.2", "Window1.2"); StubNativeMethodsForWindowInformation(NativeMethodsStub, subWindowHandle21, 201, "Class2.1", "Window2.1"); var windows = WindowFinder.FindWindows(new WindowFilterCriteria { IncludeChildWindows = true, ClassName = new Regex("Class1") }); Assert.That(windows.Length, Is.EqualTo(3)); AssertWindowInformation(windows[0], windowHandle1, 101, "Class1", "Window1"); AssertChildWindowInformation(windows[1], subWindowHandle11, 101, "Class1.1", "Window1.1", windowHandle1); AssertChildWindowInformation(windows[2], subWindowHandle12, 101, "Class1.2", "Window1.2", windowHandle1); }
public void FindWindows() { var windowHandle1 = new IntPtr(100); var windowHandle2 = new IntPtr(200); var subWindowHandle11 = new IntPtr(1001); var subWindowHandle12 = new IntPtr(1002); NativeMethodsStub.Stub(stub => stub.EnumWindows(Arg <EnumWindowsProc> .Is.NotNull, Arg <WindowFinderEnumWindowsProcContext> .Is.NotNull)) .WhenCalled( mi => { Assert.That(InvokeEnumWindowsProc(mi, windowHandle1), Is.True); Assert.That(InvokeEnumWindowsProc(mi, windowHandle2), Is.True); }) .Return(true); NativeMethodsStub.Stub( stub => stub.EnumChildWindows( Arg.Is(windowHandle1), Arg <EnumChildWindowsProc> .Is.NotNull, Arg <WindowFinderEnumChildWindowsProcContext> .Is.NotNull)) .WhenCalled( mi => { Assert.That(InvokeEnumChildWindowsProc(mi, subWindowHandle11), Is.True); Assert.That(InvokeEnumChildWindowsProc(mi, subWindowHandle12), Is.True); }); StubNativeMethodsForWindowInformation(NativeMethodsStub, windowHandle1, CurrentProcessID, "Class1", "Window1"); StubNativeMethodsForWindowInformation(NativeMethodsStub, windowHandle2, 201, "Class2", "Window2"); StubNativeMethodsForWindowInformation(NativeMethodsStub, subWindowHandle11, 101, "Class1.1", "Window1.1"); StubNativeMethodsForWindowInformation(NativeMethodsStub, subWindowHandle12, 101, "Class1.2", "Window1.2"); var windows = WindowFinder.FindWindows(new WindowFilterCriteria()); Assert.That(windows.Length, Is.EqualTo(2)); AssertWindowInformation(windows[0], windowHandle1, CurrentProcessID, "Class1", "Window1"); AssertWindowInformation(windows[1], windowHandle2, 201, "Class2", "Window2"); }