diff --git a/src/Slice.Net-Example/App.config b/src/Slice.Net-Example/App.config new file mode 100644 index 0000000..d14628f --- /dev/null +++ b/src/Slice.Net-Example/App.config @@ -0,0 +1,14 @@ + + + + + + + + + \ No newline at end of file diff --git a/src/Slice.Net-Example/App.xaml b/src/Slice.Net-Example/App.xaml new file mode 100644 index 0000000..87626c8 --- /dev/null +++ b/src/Slice.Net-Example/App.xaml @@ -0,0 +1,16 @@ + + + + + + + diff --git a/src/Slice.Net-Example/App.xaml.cs b/src/Slice.Net-Example/App.xaml.cs new file mode 100644 index 0000000..a6a5614 --- /dev/null +++ b/src/Slice.Net-Example/App.xaml.cs @@ -0,0 +1,25 @@ +/* App.xaml.cs : Generic App.xaml file + * + * Copyright (C) 2024 Selim Waly. + * + * This software may be modified and distributed under the terms + * of the MIT license. See the LICENSE file for details. + */ + +using System; +using System.Collections.Generic; +using System.Configuration; +using System.Data; +using System.Linq; +using System.Threading.Tasks; +using System.Windows; + +namespace WpfWindowTest +{ + /// + /// Interaction logic for App.xaml + /// + public partial class App : Application + { + } +} diff --git a/src/Slice.Net-Example/DS.Net-Example.csproj b/src/Slice.Net-Example/DS.Net-Example.csproj new file mode 100644 index 0000000..68d85cd --- /dev/null +++ b/src/Slice.Net-Example/DS.Net-Example.csproj @@ -0,0 +1,159 @@ + + + + + Debug + AnyCPU + {2BB3EE8B-20F3-46F6-81D5-E88D5AB330BC} + WinExe + Properties + WpfWindowTest + WpfWindowTest + v4.5 + 512 + {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 4 + SAK + SAK + SAK + SAK + publish\ + true + Disk + false + Foreground + 7 + Days + false + false + true + 0 + 1.0.0.%2a + false + false + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + 4.0 + + + + + + + + MSBuild:Compile + Designer + + + MSBuild:Compile + Designer + + + App.xaml + Code + + + MainWindow.xaml + Code + + + + + Code + + + True + True + Resources.resx + + + True + Settings.settings + True + + + ResXFileCodeGenerator + Resources.Designer.cs + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + + + + + + + False + Microsoft .NET Framework 4.5 %28x86 and x64%29 + true + + + False + .NET Framework 3.5 SP1 Client Profile + false + + + False + .NET Framework 3.5 SP1 + false + + + + + {f952df70-eb71-47e8-b4bd-8336e7cc27ce} + Slice.Net + False + + + + + + + + + + + copy "$(SolutionDir)Lib\FlexServices.DisplayHelperLib.dll" "$(TargetDir)" +copy "$(SolutionDir)Lib\SliceLibrary.dll" "$(TargetDir)" + + + \ No newline at end of file diff --git a/src/Slice.Net-Example/MainWindow.xaml b/src/Slice.Net-Example/MainWindow.xaml new file mode 100644 index 0000000..b56c498 --- /dev/null +++ b/src/Slice.Net-Example/MainWindow.xaml @@ -0,0 +1,137 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + (ex: chrome) + Primary + Secondary + Force Extend + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Slice.Net-Example/MainWindow.xaml.cs b/src/Slice.Net-Example/MainWindow.xaml.cs new file mode 100644 index 0000000..a520e35 --- /dev/null +++ b/src/Slice.Net-Example/MainWindow.xaml.cs @@ -0,0 +1,208 @@ +/* MainWindow.xaml.cs : The Main window of the Demo App + * + * Copyright (C) 2024 Selim Waly. + * + * This software may be modified and distributed under the terms + * of the MIT license. See the LICENSE file for details. + */ + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; +using SliceLibrary.Extensions; +using SliceLibrary; +using System.Windows.Forms; +using Microsoft.Win32; +using System.Diagnostics; +using System.Threading; +using System.Windows.Interop; + +namespace WpfWindowTest +{ + /// + /// Interaction logic for MainWindow.xaml + /// + public partial class MainWindow : Window + { + DSLEvents events = new DSLEvents(); + public MainWindow() + { + InitializeComponent(); + + var numOfDisplays = ScreenManager.NumberOfDisplays; + numOfDisplaysLabel.Content = numOfDisplays; + if (numOfDisplays < 2) + status.Content = "Number of displays is less than 2"; + + } + + private void clone_Click(object sender, RoutedEventArgs e) + { + logStatus(ScreenManager.CloneScreens()); + } + private void extend_Click(object sender, RoutedEventArgs e) + { + logStatus(ScreenManager.ExtendScreens()); + } + private void internal_Click(object sender, RoutedEventArgs e) + { + logStatus(ScreenManager.SetInternal()); + } + private void external_Click(object sender, RoutedEventArgs e) + { + logStatus(ScreenManager.SetExternal()); + } + + private void swapScreen_Click(object sender, RoutedEventArgs e) + { + logStatus(this.SwapScreen(getAlignment())); + } + private void sendToPrimary_Click(object sender, RoutedEventArgs e) + { + logStatus(this.SendToPrimary(getAlignment())); + } + private void sendToSecondary_Click(object sender, RoutedEventArgs e) + { + logStatus(this.SendToSecondary(getAlignment())); + } + + private void align_Click(object sender, RoutedEventArgs e) + { + var align = getAlignment(); + logStatus(this.SendToScreen(this.getScreen(), align)); + + Console.WriteLine(align); + Console.WriteLine("DPI: " + ScreenManager.getDPI().X + " " + ScreenManager.getDPI().Y); + Console.WriteLine("DPI Ratio: " + ScreenManager.getDPIRatio().X + " " + ScreenManager.getDPIRatio().Y); + Console.WriteLine("Offset:" + ScreenManager.AlignmentToOffset(this, this.getScreen(), align)); + } + + private void sendProgWinToScreen_Click(object sender, RoutedEventArgs e) + { + if ((bool)forceExtend.IsChecked && ScreenManager.CurrentTopology != ScreenManager.DisplayConfigTopology.Extend) + { + var result = ScreenManager.ExtendScreens(); + logStatus(result); + if (!result) + return; + } + new DelayedActionOnWindow(this, () => logStatus( + ScreenManager.SendProgramsWindowsToScreen(progNameTextBox.Text, + ((bool)sendProgToSecondary.IsChecked) ? ScreenManager.SecondaryScreen : ScreenManager.PrimaryScreen, + getAlignment()) ) + ).Invoke(); + } + private void sendProgMainWinToScreen_Click(object sender, RoutedEventArgs e) + { + if ((bool)forceExtend.IsChecked && ScreenManager.CurrentTopology != ScreenManager.DisplayConfigTopology.Extend) + { + var result = ScreenManager.ExtendScreens(); + logStatus(result); + if (!result) + return; + } + new DelayedActionOnWindow(this, () => logStatus( + ScreenManager.SendProgramsMainWindowToScreen(progNameTextBox.Text, + ((bool)sendProgToSecondary.IsChecked) ? ScreenManager.SecondaryScreen : ScreenManager.PrimaryScreen, + getAlignment())) + ).Invoke(); + } + + private void numOfDisplay_Click(object sender, RoutedEventArgs e) + { + numOfDisplaysLabel.Content = ScreenManager.NumberOfDisplays; + logStatus(true); + } + + + private void queryScreensBtn_Click(object sender, RoutedEventArgs e) + { + foreach (var screen in Screen.AllScreens) + { + // For each screen, add the screen properties to a list box. + Console.WriteLine("Device Name: " + screen.DeviceName); + Console.WriteLine("Bounds: " + screen.Bounds.ToString()); + Console.WriteLine("Type: " + screen.GetType().ToString()); + Console.WriteLine("Working Area: " + screen.WorkingArea.ToString()); + Console.WriteLine("Primary Screen: " + screen.Primary.ToString()); + } + + IntPtr[] hwnds = ScreenManager.getWindowHandlesFromScreen(ScreenManager.SecondaryScreen); + + foreach (var hwnd in hwnds) + ScreenManager.SendToScreen(hwnd, ScreenManager.PrimaryScreen, getAlignment()); + } + + + private ScreenManager.ScreenAlignment getAlignment() + { + ScreenManager.ScreenAlignment align = ScreenManager.ScreenAlignment.None; + if ((bool)center.IsChecked) + align |= ScreenManager.ScreenAlignment.Center; + if ((bool)left.IsChecked) + align |= ScreenManager.ScreenAlignment.Left; + if ((bool)right.IsChecked) + align |= ScreenManager.ScreenAlignment.Right; + if ((bool)top.IsChecked) + align |= ScreenManager.ScreenAlignment.Top; + if ((bool)bottom.IsChecked) + align |= ScreenManager.ScreenAlignment.Bottom; + + return align; + } + + public void removePlaceHolderForProgName(object sender, RoutedEventArgs e) + { + progNameTextBox.Text = ""; + } + + public void addPlaceHolderForProgName(object sender, RoutedEventArgs e) + { + if(progNameTextBox.Text == "") + progNameTextBox.Text = "(ex: chrome)"; + } + + private void logStatus(bool result) + { + status.Content = (result) ? "ok" : "bad"; + } + + private void SendFromSecondary_Click(object sender, RoutedEventArgs e) + { + if (ScreenManager.CurrentTopology != ScreenManager.DisplayConfigTopology.Extend) + { + if ((bool)forceExtend.IsChecked) + { + var result = ScreenManager.ExtendScreens(); + logStatus(result); + if (result) + return; + } + else + { + logStatus(false); + return; + } + } + + new DelayedActionOnWindow(this, () => { IntPtr[] hwnds = ScreenManager.getWindowHandlesFromScreen(ScreenManager.SecondaryScreen); + + logStatus((from hwnd in hwnds + select ScreenManager.SendToScreen(hwnd, ScreenManager.PrimaryScreen, getAlignment())) + .All(x => x == true) + ); + }).Invoke(); + } + } +} diff --git a/src/Slice.Net-Example/Properties/AssemblyInfo.cs b/src/Slice.Net-Example/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..a301ac9 --- /dev/null +++ b/src/Slice.Net-Example/Properties/AssemblyInfo.cs @@ -0,0 +1,55 @@ +using System.Reflection; +using System.Resources; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Windows; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("Slice.Net Library - Demo App")] +[assembly: AssemblyDescription("Slice.Net Library - Demo App is an application demonstraiting the Slice.Net Library API, and with source code supplied helps developers to better utilize the library to thier solutions.")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Selim Waly")] +[assembly: AssemblyProduct("Slice.Net")] +[assembly: AssemblyCopyright("Copyright © Selim Waly 2024")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +//In order to begin building localizable applications, set +//CultureYouAreCodingWith in your .csproj file +//inside a . For example, if you are using US english +//in your source files, set the to en-US. Then uncomment +//the NeutralResourceLanguage attribute below. Update the "en-US" in +//the line below to match the UICulture setting in the project file. + +//[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)] + + +[assembly: ThemeInfo( + ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located + //(used if a resource is not found in the page, + // or application resource dictionaries) + ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located + //(used if a resource is not found in the page, + // app, or any theme specific resource dictionaries) +)] + + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/src/Slice.Net-Example/Properties/Resources.Designer.cs b/src/Slice.Net-Example/Properties/Resources.Designer.cs new file mode 100644 index 0000000..aeb275f --- /dev/null +++ b/src/Slice.Net-Example/Properties/Resources.Designer.cs @@ -0,0 +1,63 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.18449 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace WpfWindowTest.Properties { + using System; + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("WpfWindowTest.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + } +} diff --git a/src/Slice.Net-Example/Properties/Resources.resx b/src/Slice.Net-Example/Properties/Resources.resx new file mode 100644 index 0000000..af7dbeb --- /dev/null +++ b/src/Slice.Net-Example/Properties/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/src/Slice.Net-Example/Properties/Settings.Designer.cs b/src/Slice.Net-Example/Properties/Settings.Designer.cs new file mode 100644 index 0000000..96d7641 --- /dev/null +++ b/src/Slice.Net-Example/Properties/Settings.Designer.cs @@ -0,0 +1,26 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.18449 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace WpfWindowTest.Properties { + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "12.0.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default { + get { + return defaultInstance; + } + } + } +} diff --git a/src/Slice.Net-Example/Properties/Settings.settings b/src/Slice.Net-Example/Properties/Settings.settings new file mode 100644 index 0000000..033d7a5 --- /dev/null +++ b/src/Slice.Net-Example/Properties/Settings.settings @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file