Skip to content

Commit

Permalink
1.0.4
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianlungu committed Sep 21, 2020
1 parent d265d5a commit 8d81539
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 20 deletions.
4 changes: 1 addition & 3 deletions ScreenSleep/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -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">

<Window.Resources>
Expand Down
26 changes: 23 additions & 3 deletions ScreenSleep/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Interop;
Expand All @@ -10,6 +11,14 @@ namespace ScreenSleep
/// </summary>
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()
Expand All @@ -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);
}
Expand All @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions ScreenSleep/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
12 changes: 6 additions & 6 deletions ScreenSleep/obj/Debug/MainWindow.g.i.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#pragma checksum "..\..\MainWindow.xaml" "{8829d00f-11b8-4213-878b-770e8597ac16}" "B0DEF3FFFFF9CBCB00AEA7773ABAECACF41319D7CB092A6EFDAF9D369A7E7267"
#pragma checksum "..\..\MainWindow.xaml" "{8829d00f-11b8-4213-878b-770e8597ac16}" "6E4E5F5345AF0BCC63D5B77C04DB588A5D967C6957FAAF25B1CA1A18B592CA6A"
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -81,31 +81,31 @@ 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
#line hidden
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
#line hidden
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
#line hidden
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
Expand Down
12 changes: 6 additions & 6 deletions ScreenSleep/obj/Release/MainWindow.g.i.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#pragma checksum "..\..\MainWindow.xaml" "{8829d00f-11b8-4213-878b-770e8597ac16}" "B0DEF3FFFFF9CBCB00AEA7773ABAECACF41319D7CB092A6EFDAF9D369A7E7267"
#pragma checksum "..\..\MainWindow.xaml" "{8829d00f-11b8-4213-878b-770e8597ac16}" "6E4E5F5345AF0BCC63D5B77C04DB588A5D967C6957FAAF25B1CA1A18B592CA6A"
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -81,31 +81,31 @@ 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
#line hidden
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
#line hidden
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
#line hidden
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
Expand Down
20 changes: 20 additions & 0 deletions ScreenSleep/obj/Release/ScreenSleep.csproj.FileListAbsolute.txt
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 8d81539

Please sign in to comment.