diff --git a/SecondaryMonitorDetected.sln b/SecondaryMonitorDetected.sln new file mode 100644 index 0000000..ca4eff4 --- /dev/null +++ b/SecondaryMonitorDetected.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.9.34723.18 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SecondaryMonitorDetected", "SecondaryMonitorDetected\SecondaryMonitorDetected.csproj", "{232CA07C-53B2-4F10-B009-BF56A5117017}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {232CA07C-53B2-4F10-B009-BF56A5117017}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {232CA07C-53B2-4F10-B009-BF56A5117017}.Debug|Any CPU.Build.0 = Debug|Any CPU + {232CA07C-53B2-4F10-B009-BF56A5117017}.Release|Any CPU.ActiveCfg = Release|Any CPU + {232CA07C-53B2-4F10-B009-BF56A5117017}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {86E7A472-EFC9-4AD3-84BF-07A1E79550F1} + EndGlobalSection +EndGlobal diff --git a/SecondaryMonitorDetected/App.config b/SecondaryMonitorDetected/App.config new file mode 100644 index 0000000..05a15aa --- /dev/null +++ b/SecondaryMonitorDetected/App.config @@ -0,0 +1,21 @@ + + + + +
+ + + + + + + + + 1000 + + + 1 + + + + \ No newline at end of file diff --git a/SecondaryMonitorDetected/Program.cs b/SecondaryMonitorDetected/Program.cs new file mode 100644 index 0000000..ac6dea5 --- /dev/null +++ b/SecondaryMonitorDetected/Program.cs @@ -0,0 +1,31 @@ +using System; +using System.Drawing; +using System.Management; +using System.Reflection; +using System.Threading; +using System.Windows.Forms; +using SecondaryMonitorDetected.Properties; + +namespace SecondaryMonitorDetected +{ + public static class Program + { + [STAThread] + static void Main() + { + NotifyIcon icon = new NotifyIcon + { + Icon = Icon.ExtractAssociatedIcon(Assembly.GetExecutingAssembly().Location), + Text = "Affichage secondaire détecté" + }; + + ManagementObjectSearcher searcher = new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_PnPEntity where service =\"monitor\""); + + while (true) + { + icon.Visible = searcher.Get().Count > Settings.Default.NbMonitors; + Thread.Sleep(Settings.Default.Interval); + } + } + } +} diff --git a/SecondaryMonitorDetected/Properties/AssemblyInfo.cs b/SecondaryMonitorDetected/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..7048e42 --- /dev/null +++ b/SecondaryMonitorDetected/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// 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("SecondaryMonitorDetected")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("SecondaryMonitorDetected")] +[assembly: AssemblyCopyright("Copyright © Romanito 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)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("232ca07c-53b2-4f10-b009-bf56a5117017")] + +// 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/SecondaryMonitorDetected/Properties/Resources.Designer.cs b/SecondaryMonitorDetected/Properties/Resources.Designer.cs new file mode 100644 index 0000000..7e6d535 --- /dev/null +++ b/SecondaryMonitorDetected/Properties/Resources.Designer.cs @@ -0,0 +1,63 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace SecondaryMonitorDetected.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", "17.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("SecondaryMonitorDetected.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/SecondaryMonitorDetected/Properties/Resources.resx b/SecondaryMonitorDetected/Properties/Resources.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/SecondaryMonitorDetected/Properties/Resources.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/SecondaryMonitorDetected/Properties/Settings.Designer.cs b/SecondaryMonitorDetected/Properties/Settings.Designer.cs new file mode 100644 index 0000000..a36c3b7 --- /dev/null +++ b/SecondaryMonitorDetected/Properties/Settings.Designer.cs @@ -0,0 +1,44 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace SecondaryMonitorDetected.Properties { + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.9.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; + } + } + + [global::System.Configuration.ApplicationScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("1000")] + public int Interval { + get { + return ((int)(this["Interval"])); + } + } + + [global::System.Configuration.ApplicationScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("1")] + public int NbMonitors { + get { + return ((int)(this["NbMonitors"])); + } + } + } +} diff --git a/SecondaryMonitorDetected/Properties/Settings.settings b/SecondaryMonitorDetected/Properties/Settings.settings new file mode 100644 index 0000000..3c4c2e5 --- /dev/null +++ b/SecondaryMonitorDetected/Properties/Settings.settings @@ -0,0 +1,12 @@ + + + + + + 1000 + + + 1 + + + \ No newline at end of file diff --git a/SecondaryMonitorDetected/SecondaryMonitorDetected.csproj b/SecondaryMonitorDetected/SecondaryMonitorDetected.csproj new file mode 100644 index 0000000..2485aa8 --- /dev/null +++ b/SecondaryMonitorDetected/SecondaryMonitorDetected.csproj @@ -0,0 +1,85 @@ + + + + + Debug + AnyCPU + {232CA07C-53B2-4F10-B009-BF56A5117017} + WinExe + SecondaryMonitorDetected + SecondaryMonitorDetected + v4.7.2 + 512 + true + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + false + + + icon.ico + + + + + + + + + + + + + + + + + + + + + + ResXFileCodeGenerator + Resources.Designer.cs + Designer + + + True + Resources.resx + True + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + True + Settings.settings + True + + + + + + + + + + \ No newline at end of file diff --git a/SecondaryMonitorDetected/icon.ico b/SecondaryMonitorDetected/icon.ico new file mode 100644 index 0000000..8e807e6 Binary files /dev/null and b/SecondaryMonitorDetected/icon.ico differ