Skip to content

Commit 8d81539

Browse files
committed
1.0.4
1 parent d265d5a commit 8d81539

File tree

6 files changed

+58
-20
lines changed

6 files changed

+58
-20
lines changed

ScreenSleep/MainWindow.xaml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,9 @@
77
xmlns:tb="http://www.hardcodet.net/taskbar"
88
mc:Ignorable="d"
99
WindowStyle="None"
10-
WindowState="Minimized"
1110
ShowInTaskbar="False"
1211
ShowActivated="False"
13-
Visibility="Hidden"
14-
Title="MainWindow" Height="1" Width="1"
12+
Title="MainWindow" Height="0" Width="0"
1513
Loaded="MainWindow_OnLoaded">
1614

1715
<Window.Resources>

ScreenSleep/MainWindow.xaml.cs

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Runtime.InteropServices;
23
using System.Threading.Tasks;
34
using System.Windows;
45
using System.Windows.Interop;
@@ -10,6 +11,14 @@ namespace ScreenSleep
1011
/// </summary>
1112
public partial class MainWindow : Window
1213
{
14+
[DllImport("user32.dll")]
15+
static extern IntPtr SetParent(IntPtr hwnd, IntPtr hwndNewParent);
16+
17+
// https://stackoverflow.com/questions/1399037/loading-a-wpf-window-without-showing-it
18+
private const int HWND_MESSAGE = -3;
19+
private IntPtr hwnd;
20+
private IntPtr oldParent;
21+
1322
public WindowInteropHelper Helper;
1423

1524
public MainWindow()
@@ -21,9 +30,17 @@ private void MainWindow_OnLoaded(object sender, RoutedEventArgs e)
2130
Settings.SetupStartup();
2231

2332
Helper = new WindowInteropHelper(this);
33+
Helper.EnsureHandle();
34+
35+
if (PresentationSource.FromVisual(this) is HwndSource source)
36+
{
37+
source.AddHook(WndProc);
2438

25-
var source = PresentationSource.FromVisual(this) as HwndSource;
26-
source.AddHook(WndProc);
39+
hwnd = source.Handle;
40+
oldParent = SetParent(hwnd, (IntPtr) HWND_MESSAGE);
41+
Visibility = Visibility.Hidden;
42+
ShowActivated = false;
43+
}
2744

2845
Settings.SetupSleepShortcut(Helper);
2946
}
@@ -41,7 +58,10 @@ private void Settings_OnClick(object sender, RoutedEventArgs e)
4158

4259
private void TurnOff_OnClick(object sender, RoutedEventArgs e)
4360
{
44-
if (MyNotifyIcon.ContextMenu != null) MyNotifyIcon.ContextMenu.IsOpen = false;
61+
this.Dispatcher.Invoke(() =>
62+
{
63+
if (MyNotifyIcon.ContextMenu != null) MyNotifyIcon.ContextMenu.IsOpen = false;
64+
});
4565

4666
Screen.SetScreenState(ScreenState.Off);
4767
}

ScreenSleep/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,5 @@
5151
// You can specify all the values or you can default the Build and Revision Numbers
5252
// by using the '*' as shown below:
5353
// [assembly: AssemblyVersion("1.0.*")]
54-
[assembly: AssemblyVersion("1.0.0.3")]
55-
[assembly: AssemblyFileVersion("1.0.0.3")]
54+
[assembly: AssemblyVersion("1.0.0.4")]
55+
[assembly: AssemblyFileVersion("1.0.0.4")]

ScreenSleep/obj/Debug/MainWindow.g.i.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#pragma checksum "..\..\MainWindow.xaml" "{8829d00f-11b8-4213-878b-770e8597ac16}" "B0DEF3FFFFF9CBCB00AEA7773ABAECACF41319D7CB092A6EFDAF9D369A7E7267"
1+
#pragma checksum "..\..\MainWindow.xaml" "{8829d00f-11b8-4213-878b-770e8597ac16}" "6E4E5F5345AF0BCC63D5B77C04DB588A5D967C6957FAAF25B1CA1A18B592CA6A"
22
//------------------------------------------------------------------------------
33
// <auto-generated>
44
// This code was generated by a tool.
@@ -42,7 +42,7 @@ namespace ScreenSleep {
4242
public partial class MainWindow : System.Windows.Window, System.Windows.Markup.IComponentConnector {
4343

4444

45-
#line 25 "..\..\MainWindow.xaml"
45+
#line 24 "..\..\MainWindow.xaml"
4646
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
4747
internal Hardcodet.Wpf.TaskbarNotification.TaskbarIcon MyNotifyIcon;
4848

@@ -81,31 +81,31 @@ void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object
8181
{
8282
case 1:
8383

84-
#line 14 "..\..\MainWindow.xaml"
84+
#line 13 "..\..\MainWindow.xaml"
8585
((ScreenSleep.MainWindow)(target)).Loaded += new System.Windows.RoutedEventHandler(this.MainWindow_OnLoaded);
8686

8787
#line default
8888
#line hidden
8989
return;
9090
case 2:
9191

92-
#line 18 "..\..\MainWindow.xaml"
92+
#line 17 "..\..\MainWindow.xaml"
9393
((System.Windows.Controls.MenuItem)(target)).Click += new System.Windows.RoutedEventHandler(this.TurnOff_OnClick);
9494

9595
#line default
9696
#line hidden
9797
return;
9898
case 3:
9999

100-
#line 19 "..\..\MainWindow.xaml"
100+
#line 18 "..\..\MainWindow.xaml"
101101
((System.Windows.Controls.MenuItem)(target)).Click += new System.Windows.RoutedEventHandler(this.Settings_OnClick);
102102

103103
#line default
104104
#line hidden
105105
return;
106106
case 4:
107107

108-
#line 21 "..\..\MainWindow.xaml"
108+
#line 20 "..\..\MainWindow.xaml"
109109
((System.Windows.Controls.MenuItem)(target)).Click += new System.Windows.RoutedEventHandler(this.Exit_OnClick);
110110

111111
#line default

ScreenSleep/obj/Release/MainWindow.g.i.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#pragma checksum "..\..\MainWindow.xaml" "{8829d00f-11b8-4213-878b-770e8597ac16}" "B0DEF3FFFFF9CBCB00AEA7773ABAECACF41319D7CB092A6EFDAF9D369A7E7267"
1+
#pragma checksum "..\..\MainWindow.xaml" "{8829d00f-11b8-4213-878b-770e8597ac16}" "6E4E5F5345AF0BCC63D5B77C04DB588A5D967C6957FAAF25B1CA1A18B592CA6A"
22
//------------------------------------------------------------------------------
33
// <auto-generated>
44
// This code was generated by a tool.
@@ -42,7 +42,7 @@ namespace ScreenSleep {
4242
public partial class MainWindow : System.Windows.Window, System.Windows.Markup.IComponentConnector {
4343

4444

45-
#line 25 "..\..\MainWindow.xaml"
45+
#line 24 "..\..\MainWindow.xaml"
4646
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
4747
internal Hardcodet.Wpf.TaskbarNotification.TaskbarIcon MyNotifyIcon;
4848

@@ -81,31 +81,31 @@ void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object
8181
{
8282
case 1:
8383

84-
#line 14 "..\..\MainWindow.xaml"
84+
#line 13 "..\..\MainWindow.xaml"
8585
((ScreenSleep.MainWindow)(target)).Loaded += new System.Windows.RoutedEventHandler(this.MainWindow_OnLoaded);
8686

8787
#line default
8888
#line hidden
8989
return;
9090
case 2:
9191

92-
#line 18 "..\..\MainWindow.xaml"
92+
#line 17 "..\..\MainWindow.xaml"
9393
((System.Windows.Controls.MenuItem)(target)).Click += new System.Windows.RoutedEventHandler(this.TurnOff_OnClick);
9494

9595
#line default
9696
#line hidden
9797
return;
9898
case 3:
9999

100-
#line 19 "..\..\MainWindow.xaml"
100+
#line 18 "..\..\MainWindow.xaml"
101101
((System.Windows.Controls.MenuItem)(target)).Click += new System.Windows.RoutedEventHandler(this.Settings_OnClick);
102102

103103
#line default
104104
#line hidden
105105
return;
106106
case 4:
107107

108-
#line 21 "..\..\MainWindow.xaml"
108+
#line 20 "..\..\MainWindow.xaml"
109109
((System.Windows.Controls.MenuItem)(target)).Click += new System.Windows.RoutedEventHandler(this.Exit_OnClick);
110110

111111
#line default
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
D:\Programming Stuff\ScreenSleep\ScreenSleep\bin\Release\ScreenSleep.exe.config
2+
D:\Programming Stuff\ScreenSleep\ScreenSleep\bin\Release\ScreenSleep.exe
3+
D:\Programming Stuff\ScreenSleep\ScreenSleep\bin\Release\ScreenSleep.pdb
4+
D:\Programming Stuff\ScreenSleep\ScreenSleep\bin\Release\Hardcodet.Wpf.TaskbarNotification.xml
5+
D:\Programming Stuff\ScreenSleep\ScreenSleep\obj\Release\ScreenSleep.csprojAssemblyReference.cache
6+
D:\Programming Stuff\ScreenSleep\ScreenSleep\obj\Release\Settings.baml
7+
D:\Programming Stuff\ScreenSleep\ScreenSleep\obj\Release\MainWindow.g.cs
8+
D:\Programming Stuff\ScreenSleep\ScreenSleep\obj\Release\Settings.g.cs
9+
D:\Programming Stuff\ScreenSleep\ScreenSleep\obj\Release\App.g.cs
10+
D:\Programming Stuff\ScreenSleep\ScreenSleep\obj\Release\ScreenSleep_MarkupCompile.cache
11+
D:\Programming Stuff\ScreenSleep\ScreenSleep\obj\Release\ScreenSleep_MarkupCompile.lref
12+
D:\Programming Stuff\ScreenSleep\ScreenSleep\obj\Release\MainWindow.baml
13+
D:\Programming Stuff\ScreenSleep\ScreenSleep\obj\Release\ScreenSleep.g.resources
14+
D:\Programming Stuff\ScreenSleep\ScreenSleep\obj\Release\ScreenSleep.Properties.Resources.resources
15+
D:\Programming Stuff\ScreenSleep\ScreenSleep\obj\Release\ScreenSleep.csproj.GenerateResource.cache
16+
D:\Programming Stuff\ScreenSleep\ScreenSleep\obj\Release\ScreenSleep.csproj.CoreCompileInputs.cache
17+
D:\Programming Stuff\ScreenSleep\ScreenSleep\obj\Release\ScreenSleep.csproj.Fody.CopyLocal.cache
18+
D:\Programming Stuff\ScreenSleep\ScreenSleep\obj\Release\ScreenSleep.csproj.CopyComplete
19+
D:\Programming Stuff\ScreenSleep\ScreenSleep\obj\Release\ScreenSleep.exe
20+
D:\Programming Stuff\ScreenSleep\ScreenSleep\obj\Release\ScreenSleep.pdb

0 commit comments

Comments
 (0)