From 46be7dd2bb419005c057038b18fce38c2f6727c0 Mon Sep 17 00:00:00 2001 From: Jonny007-MKD Date: Sat, 5 Nov 2016 15:45:33 +0100 Subject: [PATCH] First draft --- MultiWallpaperMaker.sln | 20 ++ MultiWallpaperMaker/App.config | 6 + MultiWallpaperMaker/Device.cs | 123 +++++++ MultiWallpaperMaker/Form1.Designer.cs | 91 ++++++ MultiWallpaperMaker/Form1.cs | 155 +++++++++ MultiWallpaperMaker/Form1.resx | 120 +++++++ .../MultiWallpaperMaker.csproj | 93 ++++++ MultiWallpaperMaker/Program.cs | 22 ++ .../Properties/AssemblyInfo.cs | 36 +++ .../Properties/Resources.Designer.cs | 71 +++++ MultiWallpaperMaker/Properties/Resources.resx | 117 +++++++ .../Properties/Settings.Designer.cs | 30 ++ .../Properties/Settings.settings | 7 + MultiWallpaperMaker/ScreenAction.cs | 124 ++++++++ MultiWallpaperMaker/ScreenEx.cs | 301 ++++++++++++++++++ MultiWallpaperMaker/ScreenSettingsDevMode.cs | 183 +++++++++++ MultiWallpaperMaker/ScreenStatus.cs | 112 +++++++ 17 files changed, 1611 insertions(+) create mode 100644 MultiWallpaperMaker.sln create mode 100644 MultiWallpaperMaker/App.config create mode 100644 MultiWallpaperMaker/Device.cs create mode 100644 MultiWallpaperMaker/Form1.Designer.cs create mode 100644 MultiWallpaperMaker/Form1.cs create mode 100644 MultiWallpaperMaker/Form1.resx create mode 100644 MultiWallpaperMaker/MultiWallpaperMaker.csproj create mode 100644 MultiWallpaperMaker/Program.cs create mode 100644 MultiWallpaperMaker/Properties/AssemblyInfo.cs create mode 100644 MultiWallpaperMaker/Properties/Resources.Designer.cs create mode 100644 MultiWallpaperMaker/Properties/Resources.resx create mode 100644 MultiWallpaperMaker/Properties/Settings.Designer.cs create mode 100644 MultiWallpaperMaker/Properties/Settings.settings create mode 100644 MultiWallpaperMaker/ScreenAction.cs create mode 100644 MultiWallpaperMaker/ScreenEx.cs create mode 100644 MultiWallpaperMaker/ScreenSettingsDevMode.cs create mode 100644 MultiWallpaperMaker/ScreenStatus.cs diff --git a/MultiWallpaperMaker.sln b/MultiWallpaperMaker.sln new file mode 100644 index 0000000..88751cc --- /dev/null +++ b/MultiWallpaperMaker.sln @@ -0,0 +1,20 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2012 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MultiWallpaperMaker", "MultiWallpaperMaker\MultiWallpaperMaker.csproj", "{F688D348-5421-4744-A3B3-BF78BAC328A1}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {F688D348-5421-4744-A3B3-BF78BAC328A1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F688D348-5421-4744-A3B3-BF78BAC328A1}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F688D348-5421-4744-A3B3-BF78BAC328A1}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F688D348-5421-4744-A3B3-BF78BAC328A1}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/MultiWallpaperMaker/App.config b/MultiWallpaperMaker/App.config new file mode 100644 index 0000000..8e15646 --- /dev/null +++ b/MultiWallpaperMaker/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/MultiWallpaperMaker/Device.cs b/MultiWallpaperMaker/Device.cs new file mode 100644 index 0000000..b88ad19 --- /dev/null +++ b/MultiWallpaperMaker/Device.cs @@ -0,0 +1,123 @@ +using System; + +namespace Trigger.Classes.Device +{ + /// + /// A device. This is very abstract + /// + public class Device + { + #region Enums + /// Type of the + public enum DeviceType : byte + { + /// This is an IDE disk (HDD, SDD, ...) + IDE, + /// This is a floppy disk + Floppy, + /// This is a compact disk + CD, + /// This is a digital video disk + DVD, + /// This is a blue ray disk + BD, + /// This is a USB disk + USB, + /// This can be any disk + Any, + /// This is a screen + Screen, + } + #endregion + + #region Properties + #region Instance + /// The name of the + public string Name + { + get; + internal set; + } + + /// The Id of the + public string Id + { + get; + internal set; + } + + /// The type of the + public DeviceType Type + { + get; + internal set; + } + + /// Get the model of this disk. This is the manufacturer's name. + public string Model + { + get; + internal set; + } + + + #endregion + #endregion + + #region Constructor + /// + /// Creates an instance of this + /// + public Device(string Id) + { + this.Id = Id; + } + #endregion + + #region Operators + /// + /// Gets a unique code of this + /// + /// + public override int GetHashCode() + { + return this.Id.GetHashCode(); + } + + /// + /// + /// + /// + public static bool operator ==(Device A, Device B) + { + if ((object)A == null) + return (object)B == null; + if ((object)B == null) + return false; + + return A.Id == B.Id; + } + /// + /// + /// + /// + public static bool operator !=(Device A, Device B) + { + return !(A == B); + } + + /// + /// Compares to s (only the IDs) + /// + /// + /// + public override bool Equals(object obj) + { + Device that = obj as Device; + if (that == null) + return false; + return this.Id == that.Id; + } + #endregion + } +} diff --git a/MultiWallpaperMaker/Form1.Designer.cs b/MultiWallpaperMaker/Form1.Designer.cs new file mode 100644 index 0000000..1e3d974 --- /dev/null +++ b/MultiWallpaperMaker/Form1.Designer.cs @@ -0,0 +1,91 @@ +namespace MultiWallpaperMaker +{ + partial class Form1 + { + /// + /// Erforderliche Designervariable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Verwendete Ressourcen bereinigen. + /// + /// True, wenn verwaltete Ressourcen gelöscht werden sollen; andernfalls False. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Vom Windows Form-Designer generierter Code + + /// + /// Erforderliche Methode für die Designerunterstützung. + /// Der Inhalt der Methode darf nicht mit dem Code-Editor geändert werden. + /// + private void InitializeComponent() + { + this.pictureBox1 = new System.Windows.Forms.PictureBox(); + this.button1 = new System.Windows.Forms.Button(); + this.button3 = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit(); + this.SuspendLayout(); + // + // pictureBox1 + // + this.pictureBox1.Dock = System.Windows.Forms.DockStyle.Fill; + this.pictureBox1.Location = new System.Drawing.Point(0, 0); + this.pictureBox1.Name = "pictureBox1"; + this.pictureBox1.Size = new System.Drawing.Size(284, 262); + this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom; + this.pictureBox1.TabIndex = 0; + this.pictureBox1.TabStop = false; + // + // button1 + // + this.button1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.button1.Location = new System.Drawing.Point(227, 12); + this.button1.Name = "button1"; + this.button1.Size = new System.Drawing.Size(45, 23); + this.button1.TabIndex = 1; + this.button1.Text = "Flip X"; + this.button1.UseVisualStyleBackColor = true; + this.button1.Click += new System.EventHandler(this.button1_Click); + // + // button3 + // + this.button3.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.button3.Location = new System.Drawing.Point(227, 227); + this.button3.Name = "button3"; + this.button3.Size = new System.Drawing.Size(45, 23); + this.button3.TabIndex = 4; + this.button3.Text = "Save"; + this.button3.UseVisualStyleBackColor = true; + this.button3.Click += new System.EventHandler(this.button3_Click); + // + // Form1 + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(284, 262); + this.Controls.Add(this.button3); + this.Controls.Add(this.button1); + this.Controls.Add(this.pictureBox1); + this.Name = "Form1"; + this.Text = "Form1"; + ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.PictureBox pictureBox1; + private System.Windows.Forms.Button button1; + private System.Windows.Forms.Button button3; + } +} + diff --git a/MultiWallpaperMaker/Form1.cs b/MultiWallpaperMaker/Form1.cs new file mode 100644 index 0000000..4df27eb --- /dev/null +++ b/MultiWallpaperMaker/Form1.cs @@ -0,0 +1,155 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using Trigger.Classes.Screen; + +namespace MultiWallpaperMaker +{ + public partial class Form1 : Form + { + private string imagePath; + public string ImagePath { + get { return this.imagePath; } + set { + try { + this.Image = new Bitmap(System.Drawing.Image.FromFile(value)); + this.imagePath = value; + } catch (Exception e) { + MessageBox.Show(e.Message); + } + } + } + + public event EventHandler ImageChanged; + private Bitmap image; + public Bitmap Image { + get { return this.image; } + private set { + if ((object)this.image != null) this.image.Dispose(); + this.image = value; + if (this.ImageChanged != null) this.ImageChanged(this, new EventArgs()); + } + } + public Bitmap DisplayedImage { + get { + if ((object)this.image == null) return null; + Bitmap image = this.image.Clone() as Bitmap; + + using (Graphics g = Graphics.FromImage(image)) { + Color c = Color.FromArgb((int)((uint)new Random().Next(0x00FFFFFF) | 0xFF000000)); + SolidBrush brush = new SolidBrush(c); + Pen pen = new Pen(brush, 2); + + foreach (var screen in this.Screens) { + g.DrawRectangle(pen, this.getRectangle(screen)); + } + pen.Dispose(); + } + + return image; + } + } + + private void updateDisplay() { + if ((object)this.pictureBox1.Image != null) this.pictureBox1.Image.Dispose(); + this.pictureBox1.Image = this.DisplayedImage; + } + + public double downscale; + public double Downscale { + get { return this.downscale; } + private set { + if (this.downscale == value) return; + this.downscale = value; + if (this.DownscaleChanged != null) this.DownscaleChanged(this, new EventArgs()); + } + } + public event EventHandler DownscaleChanged; + + public Point startPoint; + public Point StartPoint + { + get { return this.startPoint; } + private set { + if (this.startPoint == value) return; + this.startPoint = value; + if (this.StartPointChanged != null) this.StartPointChanged(this, new EventArgs()); + } + } + public event EventHandler StartPointChanged; + + public List Screens { get; private set; } + + private Nullable mouseDragStart; + + public Form1() + { + InitializeComponent(); + this.AllowDrop = true; + this.DragEnter += Form1_DragEnter; + this.DragDrop += Form1_DragDrop; + this.MouseWheel += (s, e) => this.Downscale += e.Delta / 10000.0; + this.ImageChanged += (s, e) => this.updateDisplay(); + this.DownscaleChanged += (s, e) => this.updateDisplay(); + this.StartPointChanged += (s, e) => this.updateDisplay(); + this.pictureBox1.MouseDown += (s, e) => this.mouseDragStart = e.Location; + this.pictureBox1.MouseUp += (s, e) => this.mouseDragStart = null; + this.pictureBox1.MouseMove += Form1_MouseMove; + + this.Screens = Trigger.Status.Screen.AllScreens; + this.Downscale = 1; + } + + void Form1_MouseMove(object sender, MouseEventArgs e) + { + if (this.mouseDragStart == null) return; + this.StartPoint += new Size(e.Location - new Size(this.mouseDragStart.Value)); + this.mouseDragStart = e.Location; + } + + void Form1_DragEnter(object sender, DragEventArgs e) + { + if (e.Data.GetDataPresent(DataFormats.FileDrop)) e.Effect = DragDropEffects.Copy; + else e.Effect = DragDropEffects.None; + } + + void Form1_DragDrop(object sender, DragEventArgs e) + { + if (!e.Data.GetDataPresent(DataFormats.FileDrop)) return; + string[] paths = (string[])e.Data.GetData(DataFormats.FileDrop); + this.ImagePath = paths[0]; + } + + private void button1_Click(object sender, EventArgs e) + { + if ((object)this.Image == null) return; + this.Image.RotateFlip(RotateFlipType.RotateNoneFlipX); + if (this.ImageChanged != null) this.ImageChanged(this, new EventArgs()); + } + + private void button3_Click(object sender, EventArgs e) + { + if (this.Image == null) return; + string file = Path.GetDirectoryName(this.imagePath); + file = Path.Combine(file, Path.GetFileNameWithoutExtension(this.imagePath)); + + for (int i = 0; i < this.Screens.Count; i++) { + Bitmap image = this.Image.Clone(this.getRectangle(this.Screens[i]), this.Image.PixelFormat); + image.Save(file + i + ".bmp"); + } + } + + Rectangle getRectangle(ScreenEx screen) { + var location = this.StartPoint + new Size((int)(screen.Bounds.Location.X * this.Downscale), (int)(screen.Bounds.Location.Y * this.Downscale)); + var size = new Size((int)(screen.Bounds.Size.Width * this.Downscale), (int)(screen.Bounds.Size.Height * this.Downscale)); + return new Rectangle(location, size); + } + } +} diff --git a/MultiWallpaperMaker/Form1.resx b/MultiWallpaperMaker/Form1.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/MultiWallpaperMaker/Form1.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/MultiWallpaperMaker/MultiWallpaperMaker.csproj b/MultiWallpaperMaker/MultiWallpaperMaker.csproj new file mode 100644 index 0000000..5c1eff3 --- /dev/null +++ b/MultiWallpaperMaker/MultiWallpaperMaker.csproj @@ -0,0 +1,93 @@ + + + + + Debug + AnyCPU + {F688D348-5421-4744-A3B3-BF78BAC328A1} + WinExe + Properties + MultiWallpaperMaker + MultiWallpaperMaker + v4.5 + 512 + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + Form + + + Form1.cs + + + + + + + + + Form1.cs + + + ResXFileCodeGenerator + Resources.Designer.cs + Designer + + + True + Resources.resx + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + True + Settings.settings + True + + + + + + + + \ No newline at end of file diff --git a/MultiWallpaperMaker/Program.cs b/MultiWallpaperMaker/Program.cs new file mode 100644 index 0000000..4f738ca --- /dev/null +++ b/MultiWallpaperMaker/Program.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace MultiWallpaperMaker +{ + static class Program + { + /// + /// Der Haupteinstiegspunkt für die Anwendung. + /// + [STAThread] + static void Main() + { + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(new Form1()); + } + } +} diff --git a/MultiWallpaperMaker/Properties/AssemblyInfo.cs b/MultiWallpaperMaker/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..2bb74fe --- /dev/null +++ b/MultiWallpaperMaker/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// Allgemeine Informationen über eine Assembly werden über die folgenden +// Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern, +// die mit einer Assembly verknüpft sind. +[assembly: AssemblyTitle("MultiWallpaperMaker")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("MultiWallpaperMaker")] +[assembly: AssemblyCopyright("Copyright © 2016")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Durch Festlegen von ComVisible auf "false" werden die Typen in dieser Assembly unsichtbar +// für COM-Komponenten. Wenn Sie auf einen Typ in dieser Assembly von +// COM zugreifen müssen, legen Sie das ComVisible-Attribut für diesen Typ auf "true" fest. +[assembly: ComVisible(false)] + +// Die folgende GUID bestimmt die ID der Typbibliothek, wenn dieses Projekt für COM verfügbar gemacht wird +[assembly: Guid("b0c2bd4b-7045-4bff-9c98-c1519048f1bc")] + +// Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten: +// +// Hauptversion +// Nebenversion +// Buildnummer +// Revision +// +// Sie können alle Werte angeben oder die standardmäßigen Build- und Revisionsnummern +// übernehmen, indem Sie "*" eingeben: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/MultiWallpaperMaker/Properties/Resources.Designer.cs b/MultiWallpaperMaker/Properties/Resources.Designer.cs new file mode 100644 index 0000000..47bd3b9 --- /dev/null +++ b/MultiWallpaperMaker/Properties/Resources.Designer.cs @@ -0,0 +1,71 @@ +//------------------------------------------------------------------------------ +// +// Dieser Code wurde von einem Tool generiert. +// Laufzeitversion:4.0.30319.34209 +// +// Änderungen an dieser Datei können fehlerhaftes Verhalten verursachen und gehen verloren, wenn +// der Code neu generiert wird. +// +//------------------------------------------------------------------------------ + +namespace MultiWallpaperMaker.Properties +{ + + + /// + /// Eine stark typisierte Ressourcenklasse zum Suchen von lokalisierten Zeichenfolgen usw. + /// + // Diese Klasse wurde von der StronglyTypedResourceBuilder-Klasse + // über ein Tool wie ResGen oder Visual Studio automatisch generiert. + // Um einen Member hinzuzufügen oder zu entfernen, bearbeiten Sie die .ResX-Datei und führen dann ResGen + // mit der Option /str erneut aus, oder erstellen Sie Ihr VS-Projekt neu. + [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() + { + } + + /// + /// Gibt die zwischengespeicherte ResourceManager-Instanz zurück, die von dieser Klasse verwendet wird. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager + { + get + { + if ((resourceMan == null)) + { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("MultiWallpaperMaker.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Überschreibt die CurrentUICulture-Eigenschaft des aktuellen Threads für alle + /// Ressourcenlookups, die diese stark typisierte Ressourcenklasse verwenden. + /// + [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/MultiWallpaperMaker/Properties/Resources.resx b/MultiWallpaperMaker/Properties/Resources.resx new file mode 100644 index 0000000..af7dbeb --- /dev/null +++ b/MultiWallpaperMaker/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/MultiWallpaperMaker/Properties/Settings.Designer.cs b/MultiWallpaperMaker/Properties/Settings.Designer.cs new file mode 100644 index 0000000..7b2f6b0 --- /dev/null +++ b/MultiWallpaperMaker/Properties/Settings.Designer.cs @@ -0,0 +1,30 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.34209 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace MultiWallpaperMaker.Properties +{ + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.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/MultiWallpaperMaker/Properties/Settings.settings b/MultiWallpaperMaker/Properties/Settings.settings new file mode 100644 index 0000000..3964565 --- /dev/null +++ b/MultiWallpaperMaker/Properties/Settings.settings @@ -0,0 +1,7 @@ + + + + + + + diff --git a/MultiWallpaperMaker/ScreenAction.cs b/MultiWallpaperMaker/ScreenAction.cs new file mode 100644 index 0000000..e46d042 --- /dev/null +++ b/MultiWallpaperMaker/ScreenAction.cs @@ -0,0 +1,124 @@ +using System.Runtime.InteropServices; +using Trigger.Classes.Screen; +using System; + +namespace Trigger.Actions +{ + /// + /// Actions dealing with screens and screen settings + /// + public class Screen + { + #region Enums + internal enum DispChange : sbyte + { + /// The settings change was successful. + SUCCESSFUL = 0, + /// The computer must be restarted for the graphics mode to work. + RESTART = 1, + /// The display driver failed the specified graphics mode. + FAILED = -1, + /// The graphics mode is not supported. + BADMODE = -2, + /// Unable to write settings to the registry. + NOTUPDATED = -3, + /// An invalid set of flags was passed in. + BADFLAGS = -4, + /// An invalid parameter was passed in. This can include an invalid flag or combination of flags. + BADPARAM = -5, + /// The settings change was unsuccessful because the system is DualView capable. + BADDUALVIEW = -6, + } + /// + /// Indicates how the graphics mode should be changed + /// + [Flags] + internal enum CDS : int + { + ///The mode is temporary in nature.If you change to and from another desktop, this mode will not be reset. + FULLSCREEN = 0x00000004, + ///The settings will be saved in the global settings area so that they will affect all users on the machine. Otherwise, only the settings for the user are modified. This flag is only valid when specified with the UPDATEREGISTRY flag. + GLOBAL = 0x00000008, + ///The settings will be saved in the registry, but will not take effect. This flag is only valid when specified with the UPDATEREGISTRY flag. + NORESET = 0x10000000, + ///The settings should be changed, even if the requested settings are the same as the current settings. + RESET = 0x40000000, + /// + RESET_EX = 0x20000000, + ///This device will become the primary device. + SET_PRIMARY = 0x00000010, + ///The system tests if the requested graphics mode could be set. + TEST = 0x00000002, + ///The graphics mode for the current screen will be changed dynamically and the graphics mode will be updated in the registry. The mode information is stored in the USER profile. + UPDATEREGISTRY = 0x00000001, + ///When set, the lParam parameter is a pointer to a VIDEOPARAMETERS structure. + VIDEOPARAMETERS = 0x00000020, + ///Enables settings changes to unsafe graphics modes. + ENABLE_UNSAFE_MODES = 0x00000100, + ///Disables settings changes to unsafe graphics modes. + DISABLE_UNSAFE_MODES = 0x00000200, + } + #endregion + + #region Dll imports + /// + /// The ChangeDisplaySettingsEx function changes the settings of the specified display device to the specified graphics mode. + /// + /// + /// String that specifies the display device whose graphics mode will change. Only display device names as returned by EnumDisplayDevices are valid. + /// The parameter can be NULL. A NULL value specifies the default display device. The default device can be determined by calling EnumDisplayDevices and checking for the DISPLAY_DEVICE_PRIMARY_DEVICE flag. + /// + /// A pointer to a structure that describes the new graphics mode. If is NULL, all the values currently in the registry will be used for the display setting. Passing NULL for the parameter and 0 for the parameter is the easiest way to return to the default mode after a dynamic mode change. + /// + /// + /// + /// + [DllImport("user32.dll", CharSet = CharSet.Unicode)] + internal static extern int ChangeDisplaySettingsEx(string lpszDeviceName, ref ScreenSettingsDevMode lpDevMode, IntPtr hwnd, int dwFlags, IntPtr lParam); + #endregion + + #region Methods + /// + /// The ChangeDisplaySettingsEx function changes the settings of the specified display device to the specified graphics mode. + /// Use this one if you are not sure + /// + /// + /// String that specifies the display device whose graphics mode will change. Only display device names as returned by EnumDisplayDevices are valid. + /// The parameter can be NULL. A NULL value specifies the default display device. The default device can be determined by calling EnumDisplayDevices and checking for the DISPLAY_DEVICE_PRIMARY_DEVICE flag. + /// + /// A pointer to a structure that describes the new graphics mode. If is NULL, all the values currently in the registry will be used for the display setting. Passing NULL for the parameter and 0 for the parameter is the easiest way to return to the default mode after a dynamic mode change. + /// + /// + internal static DispChange ChangeDisplaySettingsEx(string deviceName, ref ScreenSettingsDevMode devMode, CDS dwFlags) + { + return (DispChange)ChangeDisplaySettingsEx(deviceName, ref devMode, IntPtr.Zero, (int)dwFlags, IntPtr.Zero); + } + + /// + /// Updates the screen's settings + /// + /// + /// + public static bool UpdateScreen(ScreenEx screen) + { + ScreenSettingsDevMode devMode = screen.ToDEVMODE(); + DispChange result = ChangeDisplaySettingsEx(screen.Name, ref devMode, CDS.RESET | CDS.UPDATEREGISTRY); + if (result >= 0) + return true; + else + return false; + } + + /// + /// Updates the screen's settings and sets it as primary screen + /// + /// + /// + public static bool UpdateScreenAndMakePrimary(ScreenEx screen) + { + ScreenSettingsDevMode devMode = screen.ToDEVMODE(); + return ChangeDisplaySettingsEx(screen.Name, ref devMode, CDS.RESET | CDS.UPDATEREGISTRY | CDS.SET_PRIMARY) >= 0; + } + #endregion + } +} \ No newline at end of file diff --git a/MultiWallpaperMaker/ScreenEx.cs b/MultiWallpaperMaker/ScreenEx.cs new file mode 100644 index 0000000..3f628f9 --- /dev/null +++ b/MultiWallpaperMaker/ScreenEx.cs @@ -0,0 +1,301 @@ +using System; +using Systemm = System; +using Forms = System.Windows.Forms; +using System.Windows.Forms; +using System.Drawing; + +namespace Trigger.Classes.Screen +{ + /// For fixed-resolution display devices only, how the display presents a low-resolution mode on a higher-resolution display. For example, if a display device's resolution is fixed at 1024 x 768 pixels but its mode is set to 640 x 480 pixels, the device can either display a 640 x 480 image somewhere in the interior of the 1024 x 768 screen space or stretch the 640 x 480 image to fill the larger screen space + public enum FixedOutput : byte + { + /// The display's default setting. + Default = 0, + /// The low-resolution image is centered in the larger screen space. + Stretch = 1, + /// The low-resolution image is stretched to fill the larger screen space. + Center = 2, + } + /// Specifies the color resolution, in bits per pixel, of the display device + public enum ColorDepth : byte + { + /// 4 Bit -> 16 Colors + _16_Colors = 4, + /// 4 Bit -> 16 Colors + _4bit = 4, + /// 8 Bit -> 256 Colors + _256_Colors = 8, + /// 8 Bit -> 256 Colors + _8bit = 8, + /// 16 Bit -> 65.536 Colors + _65536_Colors = 16, + /// 16 Bit -> 65.536 Colors + _16bit = 16, + /// 32 Bit -> 4.294.967.296 Colors + _4294967296_Colors = 32, + /// 32 Bit -> 4.294.967.296 Colors + _32bit = 32, + } + + /// A class that provides more information than + public class ScreenEx : Device.Device // : Forms.Screen + { + #region Properties + /// Gets the bounds of the display. + private Rectangle bounds; + /// Gets the bounds of the display. + public Rectangle Bounds + { + get { return bounds; } + set + { + bounds = value; + this.fields |= DM.PELSWIDTH | DM.PELSHEIGHT; + } + } + /// Specifies the color resolution, in bits per pixel, of the display device + private byte bitsPerPixel; + /// Specifies the color resolution, in bits per pixel, of the display device + public byte BitsPerPixel + { + get { return bitsPerPixel; } + set + { + bitsPerPixel = value; + fields |= DM.BITSPERPEL; + } + } + /// Specifies the color resolution, in bits per pixel, of the display device + public ColorDepth ColorDepth + { + get { return (ColorDepth)this.BitsPerPixel; } + set { this.BitsPerPixel = (byte)value; } + } + /// Gets a value indicating whether a particular display is the primary device. + private bool primary; + /// Gets a value indicating whether a particular display is the primary device. + public bool Primary + { + get { return primary; } + private set { primary = value; } + } + /// The version number of the initialization data specification on which the structure is based + private short specVersion; + /// The version number of the initialization data specification on which the structure is based + public short SpecVersion + { + get { return specVersion; } + private set { specVersion = value; } + } + /// The driver version number assigned by the driver developer + private short driverVersion; + /// The driver version number assigned by the driver developer + public short DriverVersion + { + get { return driverVersion; } + private set { driverVersion = value; } + } + /// For display devices only, the orientation at which images should be presented. + private Forms.ScreenOrientation orientation; + /// For display devices only, the orientation at which images should be presented. + public Forms.ScreenOrientation Orientation + { + get { return orientation; } + set + { + orientation = value; + fields |= DM.DISPLAYORIENTATION; + } + } + /// For fixed-resolution display devices only, how the display presents a low-resolution mode on a higher-resolution display. For example, if a display device's resolution is fixed at 1024 x 768 pixels but its mode is set to 640 x 480 pixels, the device can either display a 640 x 480 image somewhere in the interior of the 1024 x 768 screen space or stretch the 640 x 480 image to fill the larger screen space + private FixedOutput fixedOutput; + /// For fixed-resolution display devices only, how the display presents a low-resolution mode on a higher-resolution display. For example, if a display device's resolution is fixed at 1024 x 768 pixels but its mode is set to 640 x 480 pixels, the device can either display a 640 x 480 image somewhere in the interior of the 1024 x 768 screen space or stretch the 640 x 480 image to fill the larger screen space + public FixedOutput FixedOutput + { + get { return fixedOutput; } + set + { + fixedOutput = value; + fields |= DM.DISPLAYFIXEDOUTPUT; + } + } + /// The number of pixels per logical inch. + private short logPixels; + /// The number of pixels per logical inch. + public short LogPixels + { + get { return logPixels; } + set + { + logPixels = value; + fields |= DM.LOGPIXELS; + } + } + /// Specifies the device's display mode. This member can be a combination of the following values. + /// + /// GRAYSCALE: Specifies that the display is a noncolor device. If this flag is not set, color is assumed. + /// INTERLACED: Specifies that the display mode is interlaced. If the flag is not set, noninterlaced is assumed. + /// + private int displayFlags; + /// Specifies the device's display mode. This member can be a combination of the following values. + /// + /// GRAYSCALE: Specifies that the display is a noncolor device. If this flag is not set, color is assumed. + /// INTERLACED: Specifies that the display mode is interlaced. If the flag is not set, noninterlaced is assumed. + /// + public int DisplayFlags + { + get { return displayFlags; } + set + { + displayFlags = value; + fields |= DM.DISPLAYFLAGS; + } + } + /// + /// Specifies the frequency, in hertz (cycles per second), of the display device in a particular mode. This value is also known as the display device's vertical refresh rate. Display drivers use this member. It is used, for example, in the ChangeDisplaySettings function. Printer drivers do not use this member. + /// May be the value 0 or 1. These values represent the display hardware's default refresh rate. This default rate is typically set by switches on a display card or computer motherboard, or by a configuration program that does not use display functions such as ChangeDisplaySettings. + /// + private byte frequency; + /// + /// Specifies the frequency, in hertz (cycles per second), of the display device in a particular mode. This value is also known as the display device's vertical refresh rate. Display drivers use this member. It is used, for example, in the ChangeDisplaySettings function. Printer drivers do not use this member. + /// May be the value 0 or 1. These values represent the display hardware's default refresh rate. This default rate is typically set by switches on a display card or computer motherboard, or by a configuration program that does not use display functions such as ChangeDisplaySettings. + /// + public byte Frequency + { + get { return frequency; } + set + { + frequency = value; + fields |= DM.DISPLAYFREQUENCY; + } + } + + /// Specifies whether certain members of the DEVMODE structure have been initialized. If a member is initialized, its corresponding bit is set, otherwise the bit is clear. A driver supports only those DEVMODE members that are appropriate for the printer or display technology. + /// http://msdn.microsoft.com/en-us/library/windows/desktop/dd183565%28v=vs.85%29.aspx + private DM fields = 0; + #endregion + + #region enum Field + /// + /// Specifies whether certain members of the DEVMODE structure have been initialized. If a member is initialized, its corresponding bit is set, otherwise the bit is clear. A driver supports only those DEVMODE members that are appropriate for the printer or display technology. + /// + [Flags] + private enum DM : int + { + /// + ORIENTATION = 0x00000001, + /// + PAPERSIZE = 0x00000002, + /// + PAPERLENGTH = 0x00000004, + /// + PAPERWIDTH = 0x00000008, + /// + SCALE = 0x00000010, + /// + COPIES = 0x00000100, + /// + DEFAULTSOURCE = 0x00000200, + /// + PRINTQUALITY = 0x00000400, + /// + POSITION = 0x00000020, + /// + DISPLAYORIENTATION = 0x00000080, + /// + DISPLAYFIXEDOUTPUT = 0x20000000, + /// + COLOR = 0x00000800, + /// + DUPLEX = 0x00001000, + /// + YRESOLUTION = 0x00002000, + /// + TTOPTION = 0x00004000, + /// + COLLATE = 0x00008000, + /// + FORMNAME = 0x00010000, + /// + LOGPIXELS = 0x00020000, + /// + BITSPERPEL = 0x00040000, + /// + PELSWIDTH = 0x00080000, + /// + PELSHEIGHT = 0x00100000, + /// + DISPLAYFLAGS = 0x00200000, + /// + NUP = 0x00000040, + /// + DISPLAYFREQUENCY = 0x00400000, + /// + ICMMETHOD = 0x00800000, + /// + ICMINTENT = 0x01000000, + /// + MEDIATYPE = 0x02000000, + /// + DITHERTYPE = 0x04000000, + /// + PANNINGWIDTH = 0x08000000, + /// + PANNINGHEIGHT = 0x10000000, + } + #endregion + + #region Constructors + /// + /// Create a new instance of + /// + /// + /// A received from + public ScreenEx(Forms.Screen screen, ScreenSettingsDevMode devMode) : base(screen.DeviceName) + { + this.Type = DeviceType.Screen; + this.Name = screen.DeviceName; + this.BitsPerPixel = (byte)screen.BitsPerPixel; + this.Bounds = new Rectangle(screen.Bounds.Location, screen.Bounds.Size); + this.Primary = screen.Primary; + this.SpecVersion = devMode.dmSpecVersion; + this.DriverVersion = devMode.dmDriverVersion; + this.FixedOutput = (FixedOutput)devMode.dmDisplayFixedOutput; + this.LogPixels = devMode.dmLogPixels; + this.ColorDepth = (ColorDepth)devMode.dmBitsPerPel; + this.DisplayFlags = devMode.dmDisplayFlags; + this.Frequency = (byte)devMode.dmDisplayFrequency; + this.Orientation = (ScreenOrientation)devMode.dmDisplayOrientation; + this.fields = 0; + } + #endregion + + #region Methods + /// + /// Converts this class to a struct which then may be used to update the settings + /// + /// + public ScreenSettingsDevMode ToDEVMODE() + { + ScreenSettingsDevMode devMode = new ScreenSettingsDevMode(true); + devMode.dmBitsPerPel = this.BitsPerPixel; + devMode.dmDeviceName = this.Name; + devMode.dmDisplayFixedOutput = (int)this.FixedOutput; + devMode.dmDisplayFlags = this.DisplayFlags; + devMode.dmDisplayFrequency = this.Frequency; + devMode.dmDisplayOrientation = (int)this.Orientation; + devMode.dmDriverVersion = this.DriverVersion; + devMode.dmFields = (int)this.fields; + devMode.dmFormName = ""; + devMode.dmLogPixels = this.LogPixels; + devMode.dmPelsHeight = this.Bounds.Height; + devMode.dmPelsWidth = this.Bounds.Width; + devMode.dmPositionX = this.Bounds.X; + devMode.dmPositionY = this.Bounds.Y; + devMode.dmSpecVersion = this.SpecVersion; + devMode.dmSize = (short)Systemm.Runtime.InteropServices.Marshal.SizeOf(devMode); + return devMode; + } + #endregion + } +} diff --git a/MultiWallpaperMaker/ScreenSettingsDevMode.cs b/MultiWallpaperMaker/ScreenSettingsDevMode.cs new file mode 100644 index 0000000..28c8fb0 --- /dev/null +++ b/MultiWallpaperMaker/ScreenSettingsDevMode.cs @@ -0,0 +1,183 @@ +using System; +using System.Runtime.InteropServices; + +namespace Trigger.Classes.Screen +{ + /// + /// The (DEVMODE) data structure contains information about the initialization and environment of a printer or a display device. + /// Here it will only be used for screens + /// + [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] + public struct ScreenSettingsDevMode + { + /// The name of the device + [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)] + public string dmDeviceName; + + /// The version number of the initialization data specification on which the structure is based + public short dmSpecVersion; + /// The driver version number assigned by the driver developer + public short dmDriverVersion; + /// Specifies the size, in bytes, of the DEVMODE structure, not including any private driver-specific data that might follow the structure's public members. Set this member to sizeof (DEVMODE) to indicate the version of the DEVMODE structure being used. + public short dmSize; + /// Contains the number of bytes of private driver-data that follow this structure. If a device driver does not use device-specific information, set this member to zero. + public short dmDriverExtra; + /// Specifies whether certain members of the DEVMODE structure have been initialized. If a member is initialized, its corresponding bit is set, otherwise the bit is clear. A driver supports only those DEVMODE members that are appropriate for the printer or display technology. + /// http://msdn.microsoft.com/en-us/library/windows/desktop/dd183565%28v=vs.85%29.aspx + public int dmFields; + /// For display devices only, a POINTL structure that indicates the positional coordinates of the display device in reference to the desktop area. The primary display device is always located at coordinates (0,0). + public int dmPositionX; + /// For display devices only, a POINTL structure that indicates the positional coordinates of the display device in reference to the desktop area. The primary display device is always located at coordinates (0,0). + public int dmPositionY; + /// For display devices only, the orientation at which images should be presented. If DM_DISPLAYORIENTATION is not set, this member must be zero. If DM_DISPLAYORIENTATION is set, this member must be one of the following values + /// + /// DMDO_DEFAULT (0): The display orientation is the natural orientation of the display device; it should be used as the default. + /// DMDO_90 (1): The display orientation is rotated 90 degrees (measured clockwise) from DMDO_DEFAULT. + /// DMDO_180 (2): The display orientation is rotated 180 degrees (measured clockwise) from DMDO_DEFAULT. + /// DMDO_270 (3): The display orientation is rotated 270 degrees (measured clockwise) from DMDO_DEFAULT. + /// + /// Windows 2000: Not supported + public int dmDisplayOrientation; + /// For fixed-resolution display devices only, how the display presents a low-resolution mode on a higher-resolution display. For example, if a display device's resolution is fixed at 1024 x 768 pixels but its mode is set to 640 x 480 pixels, the device can either display a 640 x 480 image somewhere in the interior of the 1024 x 768 screen space or stretch the 640 x 480 image to fill the larger screen space. If DM_DISPLAYFIXEDOUTPUT is not set, this member must be zero. If DM_DISPLAYFIXEDOUTPUT is set, this member must be one of the following values + /// + /// DMDFO_DEFAULT: The display's default setting. + /// DMDFO_CENTER: The low-resolution image is centered in the larger screen space. + /// DMDFO_STRETCH: The low-resolution image is stretched to fill the larger screen space. + /// + /// Windows 2000: Not supported + public int dmDisplayFixedOutput; + /// Switches between color and monochrome on color printers. The following are the possible values: + /// DMCOLOR_COLORDMCOLOR_MONOCHROME + public short dmColor; + /// Selects duplex or double-sided printing for printers capable of duplex printing. Following are the possible values. + /// + /// DMDUP_SIMPLEX: Normal (nonduplex) printing. + /// DMDUP_HORIZONTAL: Short-edge binding, that is, the long edge of the page is horizontal. + /// DMDUP_VERTICAL: Long-edge binding, that is, the long edge of the page is vertical. + /// + public short dmDuplex; + /// Specifies the y-resolution, in dots per inch, of the printer. If the printer initializes this member, the dmPrintQuality member specifies the x-resolution, in dots per inch, of the printer. + public short dmYResolution; + /// Specifies how TrueType fonts should be printed. This member can be one of the following values. + /// + /// DMTT_BITMAP: Prints TrueType fonts as graphics. This is the default action for dot-matrix printers. + /// DMTT_DOWNLOAD: Downloads TrueType fonts as soft fonts. This is the default action for Hewlett-Packard printers that use Printer Control Language (PCL). + /// DMTT_DOWNLOAD_OUTLINE: Downloads TrueType fonts as outline soft fonts. + /// DMTT_SUBDEV: Substitutes device fonts for TrueType fonts. This is the default action for PostScript printers. + /// + public short dmTTOption; + /// Specifies whether collation should be used when printing multiple copies. (This member is ignored unless the printer driver indicates support for collation by setting the dmFields member to DM_COLLATE.) This member can be one of the following values. + /// + /// DMCOLLATE_TRUE: Collate when printing multiple copies. + /// DMCOLLATE_FALSE: Do not collate when printing multiple copies. + /// + public short dmCollate; + + /// A zero-terminated character array that specifies the name of the form to use; for example, "Letter" or "Legal". A complete set of names can be retrieved by using the EnumForms function. + [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)] + public string dmFormName; + + /// The number of pixels per logical inch. Printer drivers do not use this member. + public short dmLogPixels; + /// Specifies the color resolution, in bits per pixel, of the display device (for example: 4 bits for 16 colors, 8 bits for 256 colors, or 16 bits for 65,536 colors). Display drivers use this member, for example, in the ChangeDisplaySettings function. Printer drivers do not use this member. + public short dmBitsPerPel; + /// Specifies the width, in pixels, of the visible device surface. Display drivers use this member, for example, in the ChangeDisplaySettings function. Printer drivers do not use this member. + public int dmPelsWidth; + /// Specifies the height, in pixels, of the visible device surface. Display drivers use this member, for example, in the ChangeDisplaySettings function. Printer drivers do not use this member. + public int dmPelsHeight; + /// Specifies the device's display mode. This member can be a combination of the following values. + /// + /// DM_GRAYSCALE: Specifies that the display is a noncolor device. If this flag is not set, color is assumed. + /// DM_INTERLACED: Specifies that the display mode is interlaced. If the flag is not set, noninterlaced is assumed. + /// + public int dmDisplayFlags; + /// + /// Specifies the frequency, in hertz (cycles per second), of the display device in a particular mode. This value is also known as the display device's vertical refresh rate. Display drivers use this member. It is used, for example, in the ChangeDisplaySettings function. Printer drivers do not use this member. + /// When you call the EnumDisplaySettings function, the dmDisplayFrequency member may return with the value 0 or 1. These values represent the display hardware's default refresh rate. This default rate is typically set by switches on a display card or computer motherboard, or by a configuration program that does not use display functions such as ChangeDisplaySettings. + /// + public int dmDisplayFrequency; + /// Specifies how ICM is handled. For a non-ICM application, this member determines if ICM is enabled or disabled. For ICM applications, the system examines this member to determine how to handle ICM support. This member can be one of the following predefined values, or a driver-defined value greater than or equal to the value of DMICMMETHOD_USER. + /// + /// DMICMMETHOD_NONE: Specifies that ICM is disabled. + /// DMICMMETHOD_SYSTEM: Specifies that ICM is handled by Windows. + /// DMICMMETHOD_DRIVER: Specifies that ICM is handled by the device driver. + /// DMICMMETHOD_DEVICE: Specifies that ICM is handled by the destination device. + /// + /// The printer driver must provide a user interface for setting this member. Most printer drivers support only the DMICMMETHOD_SYSTEM or DMICMMETHOD_NONE value. Drivers for PostScript printers support all values. + public int dmICMMethod; + /// Specifies which color matching method, or intent, should be used by default. This member is primarily for non-ICM applications. ICM applications can establish intents by using the ICM functions. This member can be one of the following predefined values, or a driver defined value greater than or equal to the value of DMICM_USER. + /// + /// DMICM_ABS_COLORIMETRIC: Color matching should optimize to match the exact color requested without white point mapping. This value is most appropriate for use with proofing. + /// DMICM_COLORIMETRIC: Color matching should optimize to match the exact color requested. This value is most appropriate for use with business logos or other images when an exact color match is desired. + /// DMICM_CONTRAST: Color matching should optimize for color contrast. This value is the most appropriate choice for scanned or photographic images when dithering is desired. + /// DMICM_SATURATE: Color matching should optimize for color saturation. This value is the most appropriate choice for business graphs when dithering is not desired. + /// + public int dmICMIntent; + /// Specifies the type of media being printed on. The member can be one of the following predefined values, or a driver-defined value greater than or equal to the value of DMMEDIA_USER. + /// + /// DMMEDIA_STANDARD: Plain paper. + /// DMMEDIA_GLOSSY: Glossy paper. + /// DMMEDIA_TRANSPARENCY: Transparent film. + /// + /// To retrieve a list of the available media types for a printer, use the DeviceCapabilities function with the DC_MEDIATYPES flag. + public int dmMediaType; + /// Specifies how dithering is to be done. The member can be one of the following predefined values, or a driver-defined value greater than or equal to the value of DMDITHER_USER. + /// + /// DMDITHER_NONE: No dithering. + /// DMDITHER_COARSE: Dithering with a coarse brush. + /// DMDITHER_FINE: Dithering with a fine brush. + /// DMDITHER_LINEART: Line art dithering, a special dithering method that produces well defined borders between black, white, and gray scaling. It is not suitable for images that include continuous graduations in intensity and hue, such as scanned photographs. + /// DMDITHER_GRAYSCALE: Device does gray scaling. + /// + public int dmDitherType; + /// Not used; must be zero. + public int dmReserved1; + /// Not used; must be zero. + public int dmReserved2; + /// This member must be zero. + public int dmPanningWidth; + /// This member must be zero. + public int dmPanningHeight; + + /// + /// You really should use this constructor! + /// Alternatively you have to set dmSize manually before using it: this.dmSize = (short)Marshal.SizeOf(this); + /// + /// Does not matter + public ScreenSettingsDevMode(bool x) + { + this.dmDeviceName = new String(new char[32]); + this.dmSpecVersion = new short(); + this.dmDriverVersion = new short(); + this.dmDriverExtra = new short(); + this.dmFields = new int(); + this.dmPositionX = new int(); + this.dmPositionY = new int(); + this.dmDisplayOrientation = new int(); + this.dmDisplayFixedOutput = new int(); + this.dmColor = new short(); + this.dmDuplex = new short(); + this.dmYResolution = new short(); + this.dmTTOption = new short(); + this.dmCollate = new short(); + this.dmFormName = new String(new char[32]); + this.dmLogPixels = new short(); + this.dmBitsPerPel = new short(); + this.dmPelsWidth = new int(); + this.dmPelsHeight = new int(); + this.dmDisplayFlags = new int(); + this.dmDisplayFrequency = new int(); + this.dmICMMethod = new int(); + this.dmICMIntent = new int(); + this.dmMediaType = new int(); + this.dmDitherType = new int(); + this.dmReserved1 = 0; + this.dmReserved2 = 0; + this.dmPanningWidth = 0; + this.dmPanningHeight = 0; + this.dmSize = new short(); + + this.dmSize = (short)Marshal.SizeOf(this); + } + }; +} \ No newline at end of file diff --git a/MultiWallpaperMaker/ScreenStatus.cs b/MultiWallpaperMaker/ScreenStatus.cs new file mode 100644 index 0000000..7ec223d --- /dev/null +++ b/MultiWallpaperMaker/ScreenStatus.cs @@ -0,0 +1,112 @@ +using System; +using Systemm = System; +using System.Collections.Generic; +using System.Drawing; +using System.Drawing.Text; +using System.Windows.Forms; +using Forms = System.Windows.Forms; +using System.Runtime.InteropServices; +using Trigger.Classes.Screen; + +namespace Trigger.Status +{ + /// + /// Provides methods to examine the status of screen devices + /// + static class Screen + { + #region DllImports + /// + /// The EnumDisplaySettings function retrieves information about one of the graphics modes for a display device. To retrieve information for all the graphics modes of a display device, make a series of calls to this function. + /// The EnumDisplaySettings function sets values for the following five members: + /// + /// dmBitsPerPel + /// dmPelsWidth + /// dmPelsHeight + /// dmDisplayFlags + /// dmDisplayFrequency + /// + /// + /// + /// A pointer to a null-terminated string that specifies the display device about whose graphics mode the function will obtain information. + /// This parameter is either NULL or a DISPLAY_DEVICE.DeviceName returned from EnumDisplayDevices. A NULL value specifies the current display device on the computer on which the calling thread is running. + /// + /// The type of information to be retrieved. This value can be a graphics mode index or one of the following values. + /// + /// ENUM_CURRENT_SETTINGS + /// ENUM_REGISTRY_SETTINGS + /// + /// A pointer to a structure into which the function stores information about the specified graphics mode. Before calling EnumDisplaySettings, set the dmSize member to sizeof(DEVMODE), and set the dmDriverExtra member to indicate the size, in bytes, of the additional space available to receive private driver data. + /// If the function succeeds, the return value is nonzero. If the function fails, the return value is zero. + [DllImport("user32.dll", CharSet = CharSet.Unicode, SetLastError = true)] + private static extern int EnumDisplaySettings(string lpszDeviceName, int iModeNum, ref ScreenSettingsDevMode lpDevMode); + #endregion + + #region Properties + #region Screen + /// Gets a list of all displays on the system + public static List AllScreens + { + get + { + List allScreens = new List(Forms.Screen.AllScreens); + List allScreensEx = new List(allScreens.Count); + allScreens.ForEach(new Action(screen => allScreensEx.Add(GetScreenSettings(screen)))); + return allScreensEx; + } + } + /// Gets the primary screen + public static ScreenEx PrimaryScreen + { + get + { + return GetScreenSettings(Forms.Screen.PrimaryScreen); + } + } + + /// + /// Gets the orientation of the screen + /// But which screen? + /// + public static ScreenOrientation ScreenOrientation + { + get + { + return SystemInformation.ScreenOrientation; + } + } + #endregion + #endregion + + #region Methods + /// + /// Returns the current System status + /// + /// + public static TreeNode GetStatus() + { + TreeNode tnMain = new TreeNode("Screens (" + AllScreens.Count + ")"); + AllScreens.ForEach(new Action(screen => + { + TreeNode tnScreen = tnMain.Nodes.Add(screen.Name); + tnScreen.Nodes.Add("Primary: " + screen.Primary.ToString()); + tnScreen.Nodes.Add("Color depth: " + screen.BitsPerPixel + "bit"); + tnScreen.Nodes.Add("Resolution: " + screen.Bounds.Width + "x" + screen.Bounds.Height); + tnScreen.Nodes.Add("Position: " + screen.Bounds.X + " | " + screen.Bounds.Y); + tnScreen.Nodes.Add("Display orientation: " + screen.Orientation.ToString()); + tnScreen.Nodes.Add("Refresh rate: " + screen.Frequency); + })); + return tnMain; + } + + public static ScreenEx GetScreenSettings(Forms.Screen screen) + { + ScreenSettingsDevMode DevMode = new ScreenSettingsDevMode(true); + if (EnumDisplaySettings(screen.DeviceName, -1 /*current settings*/, ref DevMode) == 0) + throw new Exception("EnumDisplaySettings (user32.dll) returned 0"); + ScreenEx screenSettings = new ScreenEx(screen, DevMode); + return screenSettings; + } + #endregion + } +}