From 8d815393420f43f84d11fa0cd601e04335fbfc5e Mon Sep 17 00:00:00 2001 From: adrianlungu Date: Mon, 21 Sep 2020 10:35:18 +0300 Subject: [PATCH] 1.0.4 --- ScreenSleep/MainWindow.xaml | 4 +-- ScreenSleep/MainWindow.xaml.cs | 26 ++++++++++++++++--- ScreenSleep/Properties/AssemblyInfo.cs | 4 +-- ScreenSleep/obj/Debug/MainWindow.g.i.cs | 12 ++++----- ScreenSleep/obj/Release/MainWindow.g.i.cs | 12 ++++----- .../ScreenSleep.csproj.FileListAbsolute.txt | 20 ++++++++++++++ 6 files changed, 58 insertions(+), 20 deletions(-) diff --git a/ScreenSleep/MainWindow.xaml b/ScreenSleep/MainWindow.xaml index f008b57..855f97b 100644 --- a/ScreenSleep/MainWindow.xaml +++ b/ScreenSleep/MainWindow.xaml @@ -7,11 +7,9 @@ xmlns:tb="http://www.hardcodet.net/taskbar" mc:Ignorable="d" WindowStyle="None" - WindowState="Minimized" ShowInTaskbar="False" ShowActivated="False" - Visibility="Hidden" - Title="MainWindow" Height="1" Width="1" + Title="MainWindow" Height="0" Width="0" Loaded="MainWindow_OnLoaded"> diff --git a/ScreenSleep/MainWindow.xaml.cs b/ScreenSleep/MainWindow.xaml.cs index 1a5ca0a..a947888 100644 --- a/ScreenSleep/MainWindow.xaml.cs +++ b/ScreenSleep/MainWindow.xaml.cs @@ -1,4 +1,5 @@ using System; +using System.Runtime.InteropServices; using System.Threading.Tasks; using System.Windows; using System.Windows.Interop; @@ -10,6 +11,14 @@ namespace ScreenSleep /// public partial class MainWindow : Window { + [DllImport("user32.dll")] + static extern IntPtr SetParent(IntPtr hwnd, IntPtr hwndNewParent); + + // https://stackoverflow.com/questions/1399037/loading-a-wpf-window-without-showing-it + private const int HWND_MESSAGE = -3; + private IntPtr hwnd; + private IntPtr oldParent; + public WindowInteropHelper Helper; public MainWindow() @@ -21,9 +30,17 @@ private void MainWindow_OnLoaded(object sender, RoutedEventArgs e) Settings.SetupStartup(); Helper = new WindowInteropHelper(this); + Helper.EnsureHandle(); + + if (PresentationSource.FromVisual(this) is HwndSource source) + { + source.AddHook(WndProc); - var source = PresentationSource.FromVisual(this) as HwndSource; - source.AddHook(WndProc); + hwnd = source.Handle; + oldParent = SetParent(hwnd, (IntPtr) HWND_MESSAGE); + Visibility = Visibility.Hidden; + ShowActivated = false; + } Settings.SetupSleepShortcut(Helper); } @@ -41,7 +58,10 @@ private void Settings_OnClick(object sender, RoutedEventArgs e) private void TurnOff_OnClick(object sender, RoutedEventArgs e) { - if (MyNotifyIcon.ContextMenu != null) MyNotifyIcon.ContextMenu.IsOpen = false; + this.Dispatcher.Invoke(() => + { + if (MyNotifyIcon.ContextMenu != null) MyNotifyIcon.ContextMenu.IsOpen = false; + }); Screen.SetScreenState(ScreenState.Off); } diff --git a/ScreenSleep/Properties/AssemblyInfo.cs b/ScreenSleep/Properties/AssemblyInfo.cs index 3875fbb..42aed44 100644 --- a/ScreenSleep/Properties/AssemblyInfo.cs +++ b/ScreenSleep/Properties/AssemblyInfo.cs @@ -51,5 +51,5 @@ // 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.3")] -[assembly: AssemblyFileVersion("1.0.0.3")] +[assembly: AssemblyVersion("1.0.0.4")] +[assembly: AssemblyFileVersion("1.0.0.4")] diff --git a/ScreenSleep/obj/Debug/MainWindow.g.i.cs b/ScreenSleep/obj/Debug/MainWindow.g.i.cs index 360566f..b7a1751 100644 --- a/ScreenSleep/obj/Debug/MainWindow.g.i.cs +++ b/ScreenSleep/obj/Debug/MainWindow.g.i.cs @@ -1,4 +1,4 @@ -#pragma checksum "..\..\MainWindow.xaml" "{8829d00f-11b8-4213-878b-770e8597ac16}" "B0DEF3FFFFF9CBCB00AEA7773ABAECACF41319D7CB092A6EFDAF9D369A7E7267" +#pragma checksum "..\..\MainWindow.xaml" "{8829d00f-11b8-4213-878b-770e8597ac16}" "6E4E5F5345AF0BCC63D5B77C04DB588A5D967C6957FAAF25B1CA1A18B592CA6A" //------------------------------------------------------------------------------ // // This code was generated by a tool. @@ -42,7 +42,7 @@ namespace ScreenSleep { public partial class MainWindow : System.Windows.Window, System.Windows.Markup.IComponentConnector { - #line 25 "..\..\MainWindow.xaml" + #line 24 "..\..\MainWindow.xaml" [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")] internal Hardcodet.Wpf.TaskbarNotification.TaskbarIcon MyNotifyIcon; @@ -81,7 +81,7 @@ void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object { case 1: - #line 14 "..\..\MainWindow.xaml" + #line 13 "..\..\MainWindow.xaml" ((ScreenSleep.MainWindow)(target)).Loaded += new System.Windows.RoutedEventHandler(this.MainWindow_OnLoaded); #line default @@ -89,7 +89,7 @@ void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object return; case 2: - #line 18 "..\..\MainWindow.xaml" + #line 17 "..\..\MainWindow.xaml" ((System.Windows.Controls.MenuItem)(target)).Click += new System.Windows.RoutedEventHandler(this.TurnOff_OnClick); #line default @@ -97,7 +97,7 @@ void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object return; case 3: - #line 19 "..\..\MainWindow.xaml" + #line 18 "..\..\MainWindow.xaml" ((System.Windows.Controls.MenuItem)(target)).Click += new System.Windows.RoutedEventHandler(this.Settings_OnClick); #line default @@ -105,7 +105,7 @@ void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object return; case 4: - #line 21 "..\..\MainWindow.xaml" + #line 20 "..\..\MainWindow.xaml" ((System.Windows.Controls.MenuItem)(target)).Click += new System.Windows.RoutedEventHandler(this.Exit_OnClick); #line default diff --git a/ScreenSleep/obj/Release/MainWindow.g.i.cs b/ScreenSleep/obj/Release/MainWindow.g.i.cs index 360566f..b7a1751 100644 --- a/ScreenSleep/obj/Release/MainWindow.g.i.cs +++ b/ScreenSleep/obj/Release/MainWindow.g.i.cs @@ -1,4 +1,4 @@ -#pragma checksum "..\..\MainWindow.xaml" "{8829d00f-11b8-4213-878b-770e8597ac16}" "B0DEF3FFFFF9CBCB00AEA7773ABAECACF41319D7CB092A6EFDAF9D369A7E7267" +#pragma checksum "..\..\MainWindow.xaml" "{8829d00f-11b8-4213-878b-770e8597ac16}" "6E4E5F5345AF0BCC63D5B77C04DB588A5D967C6957FAAF25B1CA1A18B592CA6A" //------------------------------------------------------------------------------ // // This code was generated by a tool. @@ -42,7 +42,7 @@ namespace ScreenSleep { public partial class MainWindow : System.Windows.Window, System.Windows.Markup.IComponentConnector { - #line 25 "..\..\MainWindow.xaml" + #line 24 "..\..\MainWindow.xaml" [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")] internal Hardcodet.Wpf.TaskbarNotification.TaskbarIcon MyNotifyIcon; @@ -81,7 +81,7 @@ void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object { case 1: - #line 14 "..\..\MainWindow.xaml" + #line 13 "..\..\MainWindow.xaml" ((ScreenSleep.MainWindow)(target)).Loaded += new System.Windows.RoutedEventHandler(this.MainWindow_OnLoaded); #line default @@ -89,7 +89,7 @@ void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object return; case 2: - #line 18 "..\..\MainWindow.xaml" + #line 17 "..\..\MainWindow.xaml" ((System.Windows.Controls.MenuItem)(target)).Click += new System.Windows.RoutedEventHandler(this.TurnOff_OnClick); #line default @@ -97,7 +97,7 @@ void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object return; case 3: - #line 19 "..\..\MainWindow.xaml" + #line 18 "..\..\MainWindow.xaml" ((System.Windows.Controls.MenuItem)(target)).Click += new System.Windows.RoutedEventHandler(this.Settings_OnClick); #line default @@ -105,7 +105,7 @@ void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object return; case 4: - #line 21 "..\..\MainWindow.xaml" + #line 20 "..\..\MainWindow.xaml" ((System.Windows.Controls.MenuItem)(target)).Click += new System.Windows.RoutedEventHandler(this.Exit_OnClick); #line default diff --git a/ScreenSleep/obj/Release/ScreenSleep.csproj.FileListAbsolute.txt b/ScreenSleep/obj/Release/ScreenSleep.csproj.FileListAbsolute.txt index e69de29..cdcf08d 100644 --- a/ScreenSleep/obj/Release/ScreenSleep.csproj.FileListAbsolute.txt +++ b/ScreenSleep/obj/Release/ScreenSleep.csproj.FileListAbsolute.txt @@ -0,0 +1,20 @@ +D:\Programming Stuff\ScreenSleep\ScreenSleep\bin\Release\ScreenSleep.exe.config +D:\Programming Stuff\ScreenSleep\ScreenSleep\bin\Release\ScreenSleep.exe +D:\Programming Stuff\ScreenSleep\ScreenSleep\bin\Release\ScreenSleep.pdb +D:\Programming Stuff\ScreenSleep\ScreenSleep\bin\Release\Hardcodet.Wpf.TaskbarNotification.xml +D:\Programming Stuff\ScreenSleep\ScreenSleep\obj\Release\ScreenSleep.csprojAssemblyReference.cache +D:\Programming Stuff\ScreenSleep\ScreenSleep\obj\Release\Settings.baml +D:\Programming Stuff\ScreenSleep\ScreenSleep\obj\Release\MainWindow.g.cs +D:\Programming Stuff\ScreenSleep\ScreenSleep\obj\Release\Settings.g.cs +D:\Programming Stuff\ScreenSleep\ScreenSleep\obj\Release\App.g.cs +D:\Programming Stuff\ScreenSleep\ScreenSleep\obj\Release\ScreenSleep_MarkupCompile.cache +D:\Programming Stuff\ScreenSleep\ScreenSleep\obj\Release\ScreenSleep_MarkupCompile.lref +D:\Programming Stuff\ScreenSleep\ScreenSleep\obj\Release\MainWindow.baml +D:\Programming Stuff\ScreenSleep\ScreenSleep\obj\Release\ScreenSleep.g.resources +D:\Programming Stuff\ScreenSleep\ScreenSleep\obj\Release\ScreenSleep.Properties.Resources.resources +D:\Programming Stuff\ScreenSleep\ScreenSleep\obj\Release\ScreenSleep.csproj.GenerateResource.cache +D:\Programming Stuff\ScreenSleep\ScreenSleep\obj\Release\ScreenSleep.csproj.CoreCompileInputs.cache +D:\Programming Stuff\ScreenSleep\ScreenSleep\obj\Release\ScreenSleep.csproj.Fody.CopyLocal.cache +D:\Programming Stuff\ScreenSleep\ScreenSleep\obj\Release\ScreenSleep.csproj.CopyComplete +D:\Programming Stuff\ScreenSleep\ScreenSleep\obj\Release\ScreenSleep.exe +D:\Programming Stuff\ScreenSleep\ScreenSleep\obj\Release\ScreenSleep.pdb