├── images ├── preview-en.png └── preview-zh.png ├── SleepPreventer ├── Resources │ ├── sleep.png │ ├── Allsleep.ico │ ├── NoneSleep.ico │ └── PartSleep.ico ├── Properties │ ├── Settings.settings │ ├── AssemblyInfo.cs │ ├── Settings.Designer.cs │ ├── Resources.Designer.cs │ └── Resources.resx ├── Program.cs ├── LocalString.Designer.cs ├── MainForm.cs ├── AboutBox.cs ├── Public.cs ├── AboutBox.Designer.cs ├── MainForm.Designer.cs ├── MyNotifyIcon.cs ├── AboutBox.resx ├── Win32API.cs ├── LocalString.resx ├── LocalString.zh-CN.resx ├── SleepPreventer.csproj ├── OptionSetter.cs ├── MainForm.zh-CN.resx └── MainForm.resx ├── README.md ├── SleepPreventer.sln ├── .gitattributes └── .gitignore /images/preview-en.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/h46incon/SleepPreventer/HEAD/images/preview-en.png -------------------------------------------------------------------------------- /images/preview-zh.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/h46incon/SleepPreventer/HEAD/images/preview-zh.png -------------------------------------------------------------------------------- /SleepPreventer/Resources/sleep.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/h46incon/SleepPreventer/HEAD/SleepPreventer/Resources/sleep.png -------------------------------------------------------------------------------- /SleepPreventer/Resources/Allsleep.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/h46incon/SleepPreventer/HEAD/SleepPreventer/Resources/Allsleep.ico -------------------------------------------------------------------------------- /SleepPreventer/Resources/NoneSleep.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/h46incon/SleepPreventer/HEAD/SleepPreventer/Resources/NoneSleep.ico -------------------------------------------------------------------------------- /SleepPreventer/Resources/PartSleep.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/h46incon/SleepPreventer/HEAD/SleepPreventer/Resources/PartSleep.ico -------------------------------------------------------------------------------- /SleepPreventer/Properties/Settings.settings: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SleepPreventer 2 | Prevent your Windows system and monitor from sleeping, like Caffeine for MacOS X. 3 | Tested in Win10 x64. 4 | 5 | ## Screenshot 6 | ![preview-en](https://github.com/h46incon/SleepPreventer/blob/master/images/preview-en.png) 7 | 8 | ## Runtime environment 9 | .Net 3.5 or higher 10 | 11 | ## To developer 12 | Codes are in a complete mess. 13 | 14 | --- 15 | 16 | # 睡眠终结者 17 | 阻止Windows系统或显示器进入睡眠,如MacOS X上的软件Caffeine。 18 | Win10 64位下完成测试。 19 | 20 | ## 预览 21 | ![preview-en](https://github.com/h46incon/SleepPreventer/blob/master/images/preview-zh.png) 22 | 23 | ## 环境要求 24 | .Net 3.5 或更高版本 25 | -------------------------------------------------------------------------------- /SleepPreventer/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Windows.Forms; 5 | 6 | namespace SleepPreventer 7 | { 8 | static class Program 9 | { 10 | /// 11 | /// 应用程序的主入口点。 12 | /// 13 | [STAThread] 14 | static void Main() 15 | { 16 | Application.EnableVisualStyles(); 17 | Application.SetCompatibleTextRenderingDefault(false); 18 | //new MyNotifyIcon(); 19 | //Application.Run(); 20 | LidCloseAwakeKeeper.CheckLogError(); 21 | Application.Run(new MainForm()); 22 | 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /SleepPreventer.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2012 4 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SleepPreventer", "SleepPreventer\SleepPreventer.csproj", "{58ADD755-A57C-4B40-B1B2-1F3E697F03C2}" 5 | EndProject 6 | Global 7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 8 | Debug|Any CPU = Debug|Any CPU 9 | Release|Any CPU = Release|Any CPU 10 | EndGlobalSection 11 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 12 | {58ADD755-A57C-4B40-B1B2-1F3E697F03C2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 13 | {58ADD755-A57C-4B40-B1B2-1F3E697F03C2}.Debug|Any CPU.Build.0 = Debug|Any CPU 14 | {58ADD755-A57C-4B40-B1B2-1F3E697F03C2}.Release|Any CPU.ActiveCfg = Release|Any CPU 15 | {58ADD755-A57C-4B40-B1B2-1F3E697F03C2}.Release|Any CPU.Build.0 = Release|Any CPU 16 | EndGlobalSection 17 | GlobalSection(SolutionProperties) = preSolution 18 | HideSolutionNode = FALSE 19 | EndGlobalSection 20 | EndGlobal 21 | -------------------------------------------------------------------------------- /SleepPreventer/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // 有关程序集的常规信息通过以下 6 | // 特性集控制。更改这些特性值可修改 7 | // 与程序集关联的信息。 8 | [assembly: AssemblyTitle("SleepPreventer")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("SleepPreventer")] 13 | [assembly: AssemblyCopyright("Copyright © 2013")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // 将 ComVisible 设置为 false 使此程序集中的类型 18 | // 对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型, 19 | // 则将该类型上的 ComVisible 特性设置为 true。 20 | [assembly: ComVisible(false)] 21 | 22 | // 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID 23 | [assembly: Guid("98dc70ff-860f-45dd-a1a2-d5884d6bf3a9")] 24 | 25 | // 程序集的版本信息由下面四个值组成: 26 | // 27 | // 主版本 28 | // 次版本 29 | // 生成号 30 | // 修订号 31 | // 32 | // 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值, 33 | // 方法是按如下所示使用“*”: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.1.0.0")] 36 | [assembly: AssemblyFileVersion("1.1.0.0")] 37 | -------------------------------------------------------------------------------- /SleepPreventer/Properties/Settings.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.18052 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace SleepPreventer.Properties 12 | { 13 | 14 | 15 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 16 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] 17 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase 18 | { 19 | 20 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); 21 | 22 | public static Settings Default 23 | { 24 | get 25 | { 26 | return defaultInstance; 27 | } 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /SleepPreventer/LocalString.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // 此代码由工具生成。 4 | // 运行时版本:4.0.30319.42000 5 | // 6 | // 对此文件的更改可能会导致不正确的行为,并且如果 7 | // 重新生成代码,这些更改将会丢失。 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace SleepPreventer { 12 | using System; 13 | 14 | 15 | /// 16 | /// 一个强类型的资源类,用于查找本地化的字符串等。 17 | /// 18 | // 此类是由 StronglyTypedResourceBuilder 19 | // 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。 20 | // 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen 21 | // (以 /str 作为命令选项),或重新生成 VS 项目。 22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] 23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 25 | internal class LocalString { 26 | 27 | private static global::System.Resources.ResourceManager resourceMan; 28 | 29 | private static global::System.Globalization.CultureInfo resourceCulture; 30 | 31 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] 32 | internal LocalString() { 33 | } 34 | 35 | /// 36 | /// 返回此类使用的缓存的 ResourceManager 实例。 37 | /// 38 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 39 | internal static global::System.Resources.ResourceManager ResourceManager { 40 | get { 41 | if (object.ReferenceEquals(resourceMan, null)) { 42 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("SleepPreventer.LocalString", typeof(LocalString).Assembly); 43 | resourceMan = temp; 44 | } 45 | return resourceMan; 46 | } 47 | } 48 | 49 | /// 50 | /// 使用此强类型资源类,为所有资源查找 51 | /// 重写当前线程的 CurrentUICulture 属性。 52 | /// 53 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 54 | internal static global::System.Globalization.CultureInfo Culture { 55 | get { 56 | return resourceCulture; 57 | } 58 | set { 59 | resourceCulture = value; 60 | } 61 | } 62 | 63 | /// 64 | /// 查找类似 TTTT 的本地化字符串。 65 | /// 66 | internal static string T_Title { 67 | get { 68 | return ResourceManager.GetString("T_Title", resourceCulture); 69 | } 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.sln.docstates 8 | 9 | # Build results 10 | 11 | [Dd]ebug/ 12 | [Rr]elease/ 13 | x64/ 14 | build/ 15 | [Bb]in/ 16 | [Oo]bj/ 17 | 18 | # Enable "build/" folder in the NuGet Packages folder since NuGet packages use it for MSBuild targets 19 | !packages/*/build/ 20 | 21 | # MSTest test Results 22 | [Tt]est[Rr]esult*/ 23 | [Bb]uild[Ll]og.* 24 | 25 | *_i.c 26 | *_p.c 27 | *.ilk 28 | *.meta 29 | *.obj 30 | *.pch 31 | *.pdb 32 | *.pgc 33 | *.pgd 34 | *.rsp 35 | *.sbr 36 | *.tlb 37 | *.tli 38 | *.tlh 39 | *.tmp 40 | *.tmp_proj 41 | *.log 42 | *.vspscc 43 | *.vssscc 44 | .builds 45 | *.pidb 46 | *.log 47 | *.scc 48 | 49 | # Visual C++ cache files 50 | ipch/ 51 | *.aps 52 | *.ncb 53 | *.opensdf 54 | *.sdf 55 | *.cachefile 56 | 57 | # Visual Studio profiler 58 | *.psess 59 | *.vsp 60 | *.vspx 61 | 62 | # Guidance Automation Toolkit 63 | *.gpState 64 | 65 | # ReSharper is a .NET coding add-in 66 | _ReSharper*/ 67 | *.[Rr]e[Ss]harper 68 | 69 | # TeamCity is a build add-in 70 | _TeamCity* 71 | 72 | # DotCover is a Code Coverage Tool 73 | *.dotCover 74 | 75 | # NCrunch 76 | *.ncrunch* 77 | .*crunch*.local.xml 78 | 79 | # Installshield output folder 80 | [Ee]xpress/ 81 | 82 | # DocProject is a documentation generator add-in 83 | DocProject/buildhelp/ 84 | DocProject/Help/*.HxT 85 | DocProject/Help/*.HxC 86 | DocProject/Help/*.hhc 87 | DocProject/Help/*.hhk 88 | DocProject/Help/*.hhp 89 | DocProject/Help/Html2 90 | DocProject/Help/html 91 | 92 | # Click-Once directory 93 | publish/ 94 | 95 | # Publish Web Output 96 | *.Publish.xml 97 | 98 | # NuGet Packages Directory 99 | ## TODO: If you have NuGet Package Restore enabled, uncomment the next line 100 | #packages/ 101 | 102 | # Windows Azure Build Output 103 | csx 104 | *.build.csdef 105 | 106 | # Windows Store app package directory 107 | AppPackages/ 108 | 109 | # Others 110 | sql/ 111 | *.Cache 112 | ClientBin/ 113 | [Ss]tyle[Cc]op.* 114 | ~$* 115 | *~ 116 | *.dbmdl 117 | *.[Pp]ublish.xml 118 | *.pfx 119 | *.publishsettings 120 | 121 | # RIA/Silverlight projects 122 | Generated_Code/ 123 | 124 | # Backup & report files from converting an old project file to a newer 125 | # Visual Studio version. Backup files are not needed, because we have git ;-) 126 | _UpgradeReport_Files/ 127 | Backup*/ 128 | UpgradeLog*.XML 129 | UpgradeLog*.htm 130 | 131 | # SQL Server files 132 | App_Data/*.mdf 133 | App_Data/*.ldf 134 | 135 | 136 | #LightSwitch generated files 137 | GeneratedArtifacts/ 138 | _Pvt_Extensions/ 139 | ModelManifest.xml 140 | 141 | # ========================= 142 | # Windows detritus 143 | # ========================= 144 | 145 | # Windows image file caches 146 | Thumbs.db 147 | ehthumbs.db 148 | 149 | # Folder config file 150 | Desktop.ini 151 | 152 | # Recycle Bin used on file shares 153 | $RECYCLE.BIN/ 154 | 155 | # Mac desktop service store files 156 | .DS_Store 157 | -------------------------------------------------------------------------------- /SleepPreventer/MainForm.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel; 4 | using System.Data; 5 | using System.Drawing; 6 | using System.Linq; 7 | using System.Text; 8 | using System.Windows.Forms; 9 | using System.Runtime.InteropServices; 10 | 11 | namespace SleepPreventer 12 | { 13 | public partial class MainForm : Form 14 | { 15 | public MainForm() 16 | { 17 | InitializeComponent(); 18 | ts_setter_ = new TExcState(this.Handle); 19 | 20 | // Init option_cb_dic_ 21 | opt_cb_dic_[TExcState.AWAY_MODE] = this.checkBox1; 22 | opt_cb_dic_[TExcState.SYS_REQ] = this.checkBox2; 23 | opt_cb_dic_[TExcState.DISPLAY_REQ] = this.checkBox3; 24 | opt_cb_dic_[TExcState.AWAKE_IN_LID_CLODE] = this.checkBox4; 25 | 26 | foreach (KeyValuePair item in opt_cb_dic_) 27 | { 28 | uint opt = item.Key; 29 | CheckBox cb = item.Value; 30 | cb_opt_dic_[cb] = opt; 31 | cb.Text = Public.OptNameDic[opt]; 32 | cb.Click += new System.EventHandler(this.OptionCBClick); 33 | } 34 | this.Text = Public.LocalStrDic[Public.LocalStrID.TITLE]; 35 | SetCheckBoxState(); 36 | 37 | ts_setter_.AddValChangeCB( 38 | new TExcState.ValChangeCB(this.SetCheckBoxState)); 39 | 40 | notify_icon_ = new MyNotifyIcon(this, ts_setter_, false); 41 | } 42 | 43 | private void SetValueFromCheckBox(object obj) 44 | { 45 | CheckBox cb = (CheckBox)obj; 46 | uint value = cb_opt_dic_[cb]; 47 | if ( ! ts_setter_.TrySetState(value, cb.Checked)) { 48 | MessageBox.Show(Public.LocalStrDic[Public.LocalStrID.OPTION_NOT_SUPPORT]); 49 | } 50 | } 51 | 52 | private void SetCheckBoxState() 53 | { 54 | // Set option state 55 | uint opt = ts_setter_.State; 56 | foreach (KeyValuePair item in opt_cb_dic_) 57 | { 58 | item.Value.Checked = ((opt & item.Key) != 0); 59 | } 60 | } 61 | 62 | private void OptionCBClick(object sender, EventArgs e) 63 | { 64 | SetValueFromCheckBox(sender); 65 | } 66 | 67 | private void Form1_FormClosed(object sender, FormClosedEventArgs e) 68 | { 69 | notify_icon_.Dispose(); 70 | } 71 | 72 | protected override void WndProc(ref Message m) 73 | { 74 | if (ts_setter_ != null && ts_setter_.PreMessageFilter(ref m)) 75 | { 76 | return; 77 | } 78 | const int WM_SYSCOMMAND = 0x112; 79 | //const int SC_CLOSE = 0xF060; 80 | const int SC_MINIMIZE = 0xF020; 81 | //const int SC_MAXIMIZE = 0xF030; 82 | //if (true && (m.Msg == Win32API.WM_POWERBROADCAST) ) 83 | //{ 84 | // MessageBox.Show("Power mode Changed! wndproc"); 85 | // return; 86 | //} 87 | if (m.Msg == WM_SYSCOMMAND) 88 | { 89 | if (m.WParam.ToInt32() == SC_MINIMIZE) 90 | { 91 | this.Hide(); 92 | return; 93 | } 94 | } 95 | base.WndProc(ref m); 96 | } 97 | 98 | private void button1_Click(object sender, EventArgs e) 99 | { 100 | AboutBox about_box = new AboutBox(); 101 | about_box.Show(this); 102 | } 103 | 104 | private TExcState ts_setter_; 105 | private MyNotifyIcon notify_icon_; 106 | 107 | Dictionary opt_cb_dic_ = new Dictionary(); 108 | Dictionary cb_opt_dic_ = new Dictionary(); 109 | 110 | } 111 | } 112 | -------------------------------------------------------------------------------- /SleepPreventer/AboutBox.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel; 4 | using System.Drawing; 5 | using System.Linq; 6 | using System.Reflection; 7 | using System.Windows.Forms; 8 | 9 | namespace SleepPreventer 10 | { 11 | partial class AboutBox : Form 12 | { 13 | public AboutBox() 14 | { 15 | InitializeComponent(); 16 | this.Text = String.Format("关于 {0}", AssemblyTitle); 17 | } 18 | 19 | #region 程序集特性访问器 20 | 21 | public string AssemblyTitle 22 | { 23 | get 24 | { 25 | object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyTitleAttribute), false); 26 | if (attributes.Length > 0) 27 | { 28 | AssemblyTitleAttribute titleAttribute = (AssemblyTitleAttribute)attributes[0]; 29 | if (titleAttribute.Title != "") 30 | { 31 | return titleAttribute.Title; 32 | } 33 | } 34 | return System.IO.Path.GetFileNameWithoutExtension(Assembly.GetExecutingAssembly().CodeBase); 35 | } 36 | } 37 | 38 | public string AssemblyVersion 39 | { 40 | get 41 | { 42 | return Assembly.GetExecutingAssembly().GetName().Version.ToString(); 43 | } 44 | } 45 | 46 | public string AssemblyDescription 47 | { 48 | get 49 | { 50 | object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyDescriptionAttribute), false); 51 | if (attributes.Length == 0) 52 | { 53 | return ""; 54 | } 55 | return ((AssemblyDescriptionAttribute)attributes[0]).Description; 56 | } 57 | } 58 | 59 | public string AssemblyProduct 60 | { 61 | get 62 | { 63 | object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyProductAttribute), false); 64 | if (attributes.Length == 0) 65 | { 66 | return ""; 67 | } 68 | return ((AssemblyProductAttribute)attributes[0]).Product; 69 | } 70 | } 71 | 72 | public string AssemblyCopyright 73 | { 74 | get 75 | { 76 | object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false); 77 | if (attributes.Length == 0) 78 | { 79 | return ""; 80 | } 81 | return ((AssemblyCopyrightAttribute)attributes[0]).Copyright; 82 | } 83 | } 84 | 85 | public string AssemblyCompany 86 | { 87 | get 88 | { 89 | object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyCompanyAttribute), false); 90 | if (attributes.Length == 0) 91 | { 92 | return ""; 93 | } 94 | return ((AssemblyCompanyAttribute)attributes[0]).Company; 95 | } 96 | } 97 | #endregion 98 | 99 | private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) 100 | { 101 | string url = "http://www.cnblogs.com/h46incon/p/SleepPreventer.html"; 102 | System.Diagnostics.Process.Start(url); 103 | } 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /SleepPreventer/Public.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Runtime.InteropServices; 4 | using System.Windows.Forms; 5 | using System.Reflection; 6 | using System.Resources; 7 | 8 | namespace SleepPreventer 9 | { 10 | public class Public 11 | { 12 | public static bool PowerGetActiveSchemeWarp(out Guid guid) 13 | { 14 | IntPtr null_ptr = IntPtr.Zero; 15 | IntPtr p_guid = IntPtr.Zero; 16 | if (Win32API.PowerGetActiveScheme(null_ptr, ref p_guid) == 0) 17 | { 18 | guid = (Guid)Marshal.PtrToStructure(p_guid, typeof(Guid)); 19 | Win32API.LocalFree(p_guid); 20 | return true; 21 | } 22 | else 23 | { 24 | guid = new Guid(); 25 | return false; 26 | } 27 | } 28 | 29 | static public bool ResetSysIdle(uint option) 30 | { 31 | return Win32API.SetThreadExecutionState(option) != 0; 32 | } 33 | 34 | private IntPtr GetWindowHandle(NotifyIcon notifyIcon) 35 | { 36 | if (notifyIcon == null) 37 | { 38 | return IntPtr.Zero; 39 | } 40 | 41 | Type type = notifyIcon.GetType(); 42 | BindingFlags bf = BindingFlags.Instance | BindingFlags.NonPublic; 43 | FieldInfo fiWindow = type.GetField("window", bf); 44 | object objWindow = fiWindow.GetValue(notifyIcon); 45 | 46 | type = objWindow.GetType().BaseType; 47 | FieldInfo fiHandle = type.GetField("handle", bf); 48 | IntPtr handle = (IntPtr)fiHandle.GetValue(objWindow); 49 | return handle; 50 | } 51 | 52 | /// 53 | /// Global const variable 54 | /// 55 | public enum LocalStrID 56 | { 57 | TITLE, 58 | EXIT, 59 | OPTION_NOT_SUPPORT 60 | } 61 | 62 | public static readonly Dictionary OptNameDic; 63 | public static readonly Dictionary LocalStrDic; 64 | 65 | public static Guid GUID_SYSTEM_BUTTON_SUBGROUP = new Guid("4f971e89-eebd-4455-a8de-9e59040e7347"); 66 | public static Guid GUID_LIDCLOSE_ACTION = new Guid("5ca83367-6e45-459f-a27b-476b1d01c936"); 67 | public const uint NO_ACTION_IN_LIDCLOSE_INDEX = 0; 68 | 69 | static Public() 70 | { 71 | ResourceManager rm = new ResourceManager(typeof(LocalString)); 72 | // Load local string 73 | LocalStrDic = new Dictionary(); 74 | LocalStrDic[LocalStrID.TITLE] = rm.GetString("T_Title"); 75 | LocalStrDic[LocalStrID.EXIT] = rm.GetString("T_Exit"); 76 | 77 | // Load OptionName 78 | OptNameDic = new Dictionary(); 79 | OptNameDic[TExcState.AWAY_MODE] = rm.GetString("T_Btn_AwayMode"); 80 | OptNameDic[TExcState.SYS_REQ] = rm.GetString("T_Btn_RequireSystem"); 81 | OptNameDic[TExcState.DISPLAY_REQ] = rm.GetString("T_Btn_RequireDisplay"); 82 | OptNameDic[TExcState.AWAKE_IN_LID_CLODE] = rm.GetString("T_Btn_LidClosedAwake"); 83 | } 84 | } 85 | 86 | public class ValChangeEvent 87 | { 88 | public delegate void ValChangeCB(); 89 | protected List call_back_list_ = new List(); 90 | 91 | public void AddValChangeCB(ValChangeCB cb) 92 | { 93 | call_back_list_.Add(cb); 94 | } 95 | 96 | public bool DelValChangeCB(ValChangeCB cb) 97 | { 98 | return call_back_list_.Remove(cb); 99 | } 100 | 101 | protected void RunValChangeCB() 102 | { 103 | foreach (ValChangeCB cb in call_back_list_) 104 | { 105 | if (cb == null) 106 | { 107 | // TODO: List item can be deleted in loop? 108 | DelValChangeCB(cb); 109 | continue; 110 | } 111 | cb(); 112 | } 113 | } 114 | 115 | } 116 | } 117 | -------------------------------------------------------------------------------- /SleepPreventer/AboutBox.Designer.cs: -------------------------------------------------------------------------------- 1 | namespace SleepPreventer 2 | { 3 | partial class AboutBox 4 | { 5 | /// 6 | /// 必需的设计器变量。 7 | /// 8 | private System.ComponentModel.IContainer components = null; 9 | 10 | /// 11 | /// 清理所有正在使用的资源。 12 | /// 13 | protected override void Dispose(bool disposing) 14 | { 15 | if (disposing && (components != null)) 16 | { 17 | components.Dispose(); 18 | } 19 | base.Dispose(disposing); 20 | } 21 | 22 | #region Windows 窗体设计器生成的代码 23 | 24 | /// 25 | /// 设计器支持所需的方法 - 不要 26 | /// 使用代码编辑器修改此方法的内容。 27 | /// 28 | private void InitializeComponent() 29 | { 30 | this.pictureBox1 = new System.Windows.Forms.PictureBox(); 31 | this.label1 = new System.Windows.Forms.Label(); 32 | this.label2 = new System.Windows.Forms.Label(); 33 | this.linkLabel1 = new System.Windows.Forms.LinkLabel(); 34 | ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit(); 35 | this.SuspendLayout(); 36 | // 37 | // pictureBox1 38 | // 39 | this.pictureBox1.Image = global::SleepPreventer.Properties.Resources.sleep; 40 | this.pictureBox1.Location = new System.Drawing.Point(12, 13); 41 | this.pictureBox1.Name = "pictureBox1"; 42 | this.pictureBox1.Size = new System.Drawing.Size(35, 34); 43 | this.pictureBox1.TabIndex = 0; 44 | this.pictureBox1.TabStop = false; 45 | // 46 | // label1 47 | // 48 | this.label1.AutoSize = true; 49 | this.label1.Location = new System.Drawing.Point(53, 13); 50 | this.label1.Name = "label1"; 51 | this.label1.Size = new System.Drawing.Size(65, 12); 52 | this.label1.TabIndex = 1; 53 | this.label1.Text = "睡眠终结者"; 54 | // 55 | // label2 56 | // 57 | this.label2.AutoSize = true; 58 | this.label2.Location = new System.Drawing.Point(77, 58); 59 | this.label2.Name = "label2"; 60 | this.label2.Size = new System.Drawing.Size(71, 12); 61 | this.label2.TabIndex = 1; 62 | this.label2.Text = "by h46incon"; 63 | // 64 | // linkLabel1 65 | // 66 | this.linkLabel1.AutoSize = true; 67 | this.linkLabel1.Location = new System.Drawing.Point(53, 35); 68 | this.linkLabel1.Name = "linkLabel1"; 69 | this.linkLabel1.Size = new System.Drawing.Size(29, 12); 70 | this.linkLabel1.TabIndex = 2; 71 | this.linkLabel1.TabStop = true; 72 | this.linkLabel1.Text = "介绍"; 73 | this.linkLabel1.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.linkLabel1_LinkClicked); 74 | // 75 | // AboutBox1 76 | // 77 | this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); 78 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 79 | this.ClientSize = new System.Drawing.Size(154, 79); 80 | this.Controls.Add(this.linkLabel1); 81 | this.Controls.Add(this.label2); 82 | this.Controls.Add(this.label1); 83 | this.Controls.Add(this.pictureBox1); 84 | this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; 85 | this.MaximizeBox = false; 86 | this.MinimizeBox = false; 87 | this.Name = "AboutBox1"; 88 | this.Padding = new System.Windows.Forms.Padding(9, 8, 9, 8); 89 | this.ShowIcon = false; 90 | this.ShowInTaskbar = false; 91 | this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; 92 | this.Text = "About"; 93 | ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit(); 94 | this.ResumeLayout(false); 95 | this.PerformLayout(); 96 | 97 | } 98 | 99 | #endregion 100 | 101 | private System.Windows.Forms.PictureBox pictureBox1; 102 | private System.Windows.Forms.Label label1; 103 | private System.Windows.Forms.Label label2; 104 | private System.Windows.Forms.LinkLabel linkLabel1; 105 | 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /SleepPreventer/Properties/Resources.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // 此代码由工具生成。 4 | // 运行时版本:4.0.30319.18052 5 | // 6 | // 对此文件的更改可能会导致不正确的行为,并且如果 7 | // 重新生成代码,这些更改将会丢失。 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace SleepPreventer.Properties { 12 | using System; 13 | 14 | 15 | /// 16 | /// 一个强类型的资源类,用于查找本地化的字符串等。 17 | /// 18 | // 此类是由 StronglyTypedResourceBuilder 19 | // 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。 20 | // 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen 21 | // (以 /str 作为命令选项),或重新生成 VS 项目。 22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] 23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 25 | internal class Resources { 26 | 27 | private static global::System.Resources.ResourceManager resourceMan; 28 | 29 | private static global::System.Globalization.CultureInfo resourceCulture; 30 | 31 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] 32 | internal Resources() { 33 | } 34 | 35 | /// 36 | /// 返回此类使用的缓存的 ResourceManager 实例。 37 | /// 38 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 39 | internal static global::System.Resources.ResourceManager ResourceManager { 40 | get { 41 | if (object.ReferenceEquals(resourceMan, null)) { 42 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("SleepPreventer.Properties.Resources", typeof(Resources).Assembly); 43 | resourceMan = temp; 44 | } 45 | return resourceMan; 46 | } 47 | } 48 | 49 | /// 50 | /// 使用此强类型资源类,为所有资源查找 51 | /// 重写当前线程的 CurrentUICulture 属性。 52 | /// 53 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 54 | internal static global::System.Globalization.CultureInfo Culture { 55 | get { 56 | return resourceCulture; 57 | } 58 | set { 59 | resourceCulture = value; 60 | } 61 | } 62 | 63 | /// 64 | /// 查找类似于 (Icon) 的 System.Drawing.Icon 类型的本地化资源。 65 | /// 66 | internal static System.Drawing.Icon Allsleep { 67 | get { 68 | object obj = ResourceManager.GetObject("Allsleep", resourceCulture); 69 | return ((System.Drawing.Icon)(obj)); 70 | } 71 | } 72 | 73 | /// 74 | /// 查找类似 Config 的本地化字符串。 75 | /// 76 | internal static string ConfigFileName { 77 | get { 78 | return ResourceManager.GetString("ConfigFileName", resourceCulture); 79 | } 80 | } 81 | 82 | /// 83 | /// 查找类似于 (Icon) 的 System.Drawing.Icon 类型的本地化资源。 84 | /// 85 | internal static System.Drawing.Icon NoneSleep { 86 | get { 87 | object obj = ResourceManager.GetObject("NoneSleep", resourceCulture); 88 | return ((System.Drawing.Icon)(obj)); 89 | } 90 | } 91 | 92 | /// 93 | /// 查找类似于 (Icon) 的 System.Drawing.Icon 类型的本地化资源。 94 | /// 95 | internal static System.Drawing.Icon PartSleep { 96 | get { 97 | object obj = ResourceManager.GetObject("PartSleep", resourceCulture); 98 | return ((System.Drawing.Icon)(obj)); 99 | } 100 | } 101 | 102 | /// 103 | /// 查找 System.Drawing.Bitmap 类型的本地化资源。 104 | /// 105 | internal static System.Drawing.Bitmap sleep { 106 | get { 107 | object obj = ResourceManager.GetObject("sleep", resourceCulture); 108 | return ((System.Drawing.Bitmap)(obj)); 109 | } 110 | } 111 | } 112 | } 113 | -------------------------------------------------------------------------------- /SleepPreventer/MainForm.Designer.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace SleepPreventer 3 | { 4 | 5 | partial class MainForm 6 | { 7 | /// 8 | /// 必需的设计器变量。 9 | /// 10 | private System.ComponentModel.IContainer components = null; 11 | 12 | /// 13 | /// 清理所有正在使用的资源。 14 | /// 15 | /// 如果应释放托管资源,为 true;否则为 false。 16 | protected override void Dispose(bool disposing) 17 | { 18 | if (disposing && (components != null)) 19 | { 20 | components.Dispose(); 21 | } 22 | base.Dispose(disposing); 23 | } 24 | 25 | #region Windows 窗体设计器生成的代码 26 | 27 | /// 28 | /// 设计器支持所需的方法 - 不要 29 | /// 使用代码编辑器修改此方法的内容。 30 | /// 31 | private void InitializeComponent() 32 | { 33 | System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(MainForm)); 34 | this.checkBox1 = new System.Windows.Forms.CheckBox(); 35 | this.checkBox2 = new System.Windows.Forms.CheckBox(); 36 | this.checkBox3 = new System.Windows.Forms.CheckBox(); 37 | this.groupBox1 = new System.Windows.Forms.GroupBox(); 38 | this.button1 = new System.Windows.Forms.Button(); 39 | this.checkBox4 = new System.Windows.Forms.CheckBox(); 40 | this.groupBox2 = new System.Windows.Forms.GroupBox(); 41 | this.label1 = new System.Windows.Forms.Label(); 42 | this.groupBox1.SuspendLayout(); 43 | this.groupBox2.SuspendLayout(); 44 | this.SuspendLayout(); 45 | // 46 | // checkBox1 47 | // 48 | resources.ApplyResources(this.checkBox1, "checkBox1"); 49 | this.checkBox1.Name = "checkBox1"; 50 | this.checkBox1.UseVisualStyleBackColor = true; 51 | // 52 | // checkBox2 53 | // 54 | resources.ApplyResources(this.checkBox2, "checkBox2"); 55 | this.checkBox2.Name = "checkBox2"; 56 | this.checkBox2.UseVisualStyleBackColor = true; 57 | // 58 | // checkBox3 59 | // 60 | resources.ApplyResources(this.checkBox3, "checkBox3"); 61 | this.checkBox3.Name = "checkBox3"; 62 | this.checkBox3.UseVisualStyleBackColor = true; 63 | // 64 | // groupBox1 65 | // 66 | resources.ApplyResources(this.groupBox1, "groupBox1"); 67 | this.groupBox1.Controls.Add(this.checkBox2); 68 | this.groupBox1.Controls.Add(this.checkBox1); 69 | this.groupBox1.Controls.Add(this.checkBox3); 70 | this.groupBox1.Name = "groupBox1"; 71 | this.groupBox1.TabStop = false; 72 | // 73 | // button1 74 | // 75 | resources.ApplyResources(this.button1, "button1"); 76 | this.button1.Name = "button1"; 77 | this.button1.UseVisualStyleBackColor = true; 78 | this.button1.Click += new System.EventHandler(this.button1_Click); 79 | // 80 | // checkBox4 81 | // 82 | resources.ApplyResources(this.checkBox4, "checkBox4"); 83 | this.checkBox4.Name = "checkBox4"; 84 | this.checkBox4.UseVisualStyleBackColor = true; 85 | // 86 | // groupBox2 87 | // 88 | resources.ApplyResources(this.groupBox2, "groupBox2"); 89 | this.groupBox2.Controls.Add(this.label1); 90 | this.groupBox2.Controls.Add(this.checkBox4); 91 | this.groupBox2.Name = "groupBox2"; 92 | this.groupBox2.TabStop = false; 93 | // 94 | // label1 95 | // 96 | resources.ApplyResources(this.label1, "label1"); 97 | this.label1.Name = "label1"; 98 | // 99 | // MainForm 100 | // 101 | resources.ApplyResources(this, "$this"); 102 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 103 | this.Controls.Add(this.groupBox2); 104 | this.Controls.Add(this.groupBox1); 105 | this.Controls.Add(this.button1); 106 | this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; 107 | this.MaximizeBox = false; 108 | this.Name = "MainForm"; 109 | this.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.Form1_FormClosed); 110 | this.groupBox1.ResumeLayout(false); 111 | this.groupBox1.PerformLayout(); 112 | this.groupBox2.ResumeLayout(false); 113 | this.groupBox2.PerformLayout(); 114 | this.ResumeLayout(false); 115 | 116 | } 117 | 118 | #endregion 119 | 120 | private System.Windows.Forms.CheckBox checkBox1; 121 | private System.Windows.Forms.CheckBox checkBox2; 122 | private System.Windows.Forms.CheckBox checkBox3; 123 | private System.Windows.Forms.GroupBox groupBox1; 124 | public System.Windows.Forms.Button button1; 125 | private System.Windows.Forms.CheckBox checkBox4; 126 | private System.Windows.Forms.GroupBox groupBox2; 127 | private System.Windows.Forms.Label label1; 128 | } 129 | } 130 | 131 | -------------------------------------------------------------------------------- /SleepPreventer/MyNotifyIcon.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Windows.Forms; 6 | using System.Runtime.InteropServices; 7 | 8 | namespace SleepPreventer 9 | { 10 | 11 | public class MyNotifyIcon : IDisposable 12 | { 13 | public MyNotifyIcon(Form form, TExcState ts_setter = null, bool show_now = false) 14 | { 15 | ts_setter_ = ts_setter ?? new TExcState(); 16 | main_form_ = form; 17 | 18 | InitMenuStrip(); 19 | // Notify_icon 20 | notify_icon_ = new System.Windows.Forms.NotifyIcon(); 21 | notify_icon_.Text = Public.LocalStrDic[Public.LocalStrID.TITLE]; 22 | notify_icon_.Visible = true; 23 | notify_icon_.Click += new System.EventHandler(notifyIcon_Click); 24 | notify_icon_.ContextMenuStrip = notify_menu_; 25 | 26 | InitIcon(); 27 | // Set state 28 | SetMenuItemState(); 29 | 30 | ts_setter_.AddValChangeCB(new TExcState.ValChangeCB(this.SetMenuItemState)); 31 | 32 | if (show_now) 33 | { 34 | main_form_.Show(); 35 | } 36 | 37 | } 38 | 39 | private void notifyIcon_Click(object sender, EventArgs e) 40 | { 41 | MouseEventArgs mouse_event = (MouseEventArgs)e; 42 | // Right button is for menu strip 43 | if (mouse_event.Button == MouseButtons.Right) 44 | { 45 | return; 46 | } 47 | else 48 | { 49 | //if (main_form_.IsDisposed) 50 | //{ 51 | // main_form_ = new Form1(ts_setter_, this); 52 | // main_form_.Show(); 53 | //} 54 | //else 55 | //{ 56 | // main_form_.Close(); 57 | //} 58 | if (main_form_.Visible) 59 | { 60 | main_form_.Hide(); 61 | } 62 | else 63 | { 64 | main_form_.Show(); 65 | main_form_.Activate(); 66 | } 67 | } 68 | } 69 | 70 | private void exit_toolstripItemClick(object sender, EventArgs e) 71 | { 72 | this.Dispose(); 73 | } 74 | 75 | private void opt_menuitemClick(object sender, EventArgs e) 76 | { 77 | ToolStripMenuItem item = sender as ToolStripMenuItem; 78 | item.Checked ^= true; 79 | uint value = menuitem_opt_dic_[item]; 80 | if ( ! ts_setter_.TrySetState(value, item.Checked)) { 81 | MessageBox.Show(Public.LocalStrDic[Public.LocalStrID.OPTION_NOT_SUPPORT]); 82 | } 83 | } 84 | 85 | private void InitMenuStrip() 86 | { 87 | // New strip menu item 88 | opt_menuitem_dic_ = new Dictionary(); 89 | foreach (var opt in Public.OptNameDic.Keys) 90 | { 91 | opt_menuitem_dic_[opt] = new ToolStripMenuItem(); 92 | } 93 | exit_item_ = new ToolStripMenuItem(); 94 | 95 | // Set property 96 | menuitem_opt_dic_ = new Dictionary(); 97 | foreach (KeyValuePair item in opt_menuitem_dic_) 98 | { 99 | uint opt = item.Key; 100 | ToolStripMenuItem menu_item = item.Value; 101 | menuitem_opt_dic_[menu_item] = opt; 102 | menu_item.Text = Public.OptNameDic[opt]; 103 | menu_item.Click += new EventHandler(this.opt_menuitemClick); 104 | } 105 | exit_item_.Text = Public.LocalStrDic[Public.LocalStrID.EXIT]; 106 | exit_item_.Click += new EventHandler(this.exit_toolstripItemClick); 107 | 108 | // Notify Menu 109 | notify_menu_ = new ContextMenuStrip(); 110 | 111 | notify_menu_.Items.Add(opt_menuitem_dic_[TExcState.AWAY_MODE]); 112 | notify_menu_.Items.Add(opt_menuitem_dic_[TExcState.DISPLAY_REQ]); 113 | notify_menu_.Items.Add(opt_menuitem_dic_[TExcState.SYS_REQ]); 114 | notify_menu_.Items.Add(new ToolStripSeparator()); 115 | notify_menu_.Items.Add(opt_menuitem_dic_[TExcState.AWAKE_IN_LID_CLODE]); 116 | notify_menu_.Items.Add(new ToolStripSeparator()); 117 | notify_menu_.Items.Add(exit_item_); 118 | } 119 | 120 | private void SetMenuItemState() 121 | { 122 | foreach (KeyValuePair item in opt_menuitem_dic_) 123 | { 124 | item.Value.Checked = ((item.Key & ts_setter_.State) != 0); 125 | } 126 | // icon 127 | uint cur_opt = ts_setter_.State; 128 | if ((cur_opt & Win32API.ES_DISPLAY_REQUIRED) != 0) 129 | { 130 | notify_icon_.Icon = none_sleep_ico_; 131 | } 132 | else if ((cur_opt & Win32API.ES_SYSTEM_REQUIRED) != 0) 133 | { 134 | notify_icon_.Icon = part_sleep_ico_; 135 | } 136 | else 137 | { 138 | notify_icon_.Icon = all_sleep_ico_; 139 | } 140 | } 141 | 142 | private void InitIcon() 143 | { 144 | this.all_sleep_ico_ = Properties.Resources.Allsleep; 145 | this.part_sleep_ico_ = Properties.Resources.PartSleep; 146 | this.none_sleep_ico_ = Properties.Resources.NoneSleep; 147 | } 148 | 149 | public void Dispose() 150 | { 151 | notify_icon_.Dispose(); 152 | Application.Exit(); 153 | } 154 | private Dictionary opt_menuitem_dic_; 155 | private Dictionary menuitem_opt_dic_; 156 | private ToolStripMenuItem exit_item_; 157 | 158 | private NotifyIcon notify_icon_; 159 | private ContextMenuStrip notify_menu_; 160 | private TExcState ts_setter_; 161 | private Form main_form_; 162 | 163 | private System.Drawing.Icon all_sleep_ico_; 164 | private System.Drawing.Icon part_sleep_ico_; 165 | private System.Drawing.Icon none_sleep_ico_; 166 | } 167 | } 168 | -------------------------------------------------------------------------------- /SleepPreventer/AboutBox.resx: -------------------------------------------------------------------------------- 1 | 2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | text/microsoft-resx 110 | 111 | 112 | 2.0 113 | 114 | 115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | 118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 119 | 120 | -------------------------------------------------------------------------------- /SleepPreventer/Win32API.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Runtime.InteropServices; 6 | 7 | namespace SleepPreventer 8 | { 9 | public class Win32API 10 | { 11 | [DllImport("kernel32.dll")] 12 | public static extern 13 | uint SetThreadExecutionState(uint esFlags); 14 | 15 | public const uint ES_AWAYMODE_REQUIRED = 0x00000040; 16 | public const uint ES_CONTINUOUS = 0x80000000; 17 | public const uint ES_DISPLAY_REQUIRED = 0x00000002; 18 | public const uint ES_SYSTEM_REQUIRED = 0x00000001; 19 | public const uint ES_USER_PRESENT = 0x00000004; 20 | 21 | //http://msdn.microsoft.com/en-us/library/windows/desktop/aa366730(v=vs.85).aspx 22 | [DllImport("kernel32.dll")] 23 | public static extern 24 | IntPtr LocalFree(IntPtr hMem ); 25 | 26 | //http://msdn.microsoft.com/en-us/library/windows/desktop/aa372734(v=vs.85).aspx 27 | [DllImport("PowrProf.dll")] 28 | public static extern 29 | uint PowerReadACValue( 30 | IntPtr RootPowerKey, 31 | ref Guid SchemeGuid, 32 | ref Guid SubGroupOfPowerSettingsGuid, 33 | ref Guid PowerSettingGuid, 34 | ref uint Type, 35 | Byte[] Buffer, 36 | ref uint BufferSize 37 | ); 38 | 39 | //http://msdn.microsoft.com/en-us/library/windows/desktop/aa372734(v=vs.85).aspx 40 | [DllImport("PowrProf.dll")] 41 | public static extern 42 | uint PowerReadDCValue( 43 | IntPtr RootPowerKey, 44 | ref Guid SchemeGuid, 45 | ref Guid SubGroupOfPowerSettingsGuid, 46 | ref Guid PowerSettingGuid, 47 | ref uint Type, 48 | Byte[] Buffer, 49 | ref uint BufferSize 50 | ); 51 | 52 | //http://msdn.microsoft.com/en-us/library/windows/desktop/aa372735(v=vs.85).aspx 53 | [DllImport("PowrProf.dll")] 54 | public static extern 55 | uint PowerReadACValueIndex( 56 | IntPtr RootPowerKey, 57 | ref Guid SchemeGuid, 58 | ref Guid SubGroupOfPowerSettingsGuid, 59 | ref Guid PowerSettingGuid, 60 | ref uint AcValueIndex 61 | ); 62 | 63 | //http://msdn.microsoft.com/en-us/library/windows/desktop/aa372738(v=vs.85).aspx 64 | [DllImport("PowrProf.dll")] 65 | public static extern 66 | uint PowerReadDCValueIndex( 67 | IntPtr RootPowerKey, 68 | ref Guid SchemeGuid, 69 | ref Guid SubGroupOfPowerSettingsGuid, 70 | ref Guid PowerSettingGuid, 71 | ref uint DcValueIndex 72 | ); 73 | 74 | //http://msdn.microsoft.com/en-us/library/windows/desktop/aa372765(v=vs.85).aspx 75 | [DllImport("PowrProf.dll")] 76 | public static extern 77 | uint PowerWriteACValueIndex( 78 | IntPtr RootPowerKey, 79 | ref Guid SchemeGuid, 80 | ref Guid SubGroupOfPowerSettingsGuid, 81 | ref Guid PowerSettingGuid, 82 | uint AcValueIndex 83 | ); 84 | 85 | //http://msdn.microsoft.com/en-us/library/windows/desktop/aa372769(v=vs.85).aspx 86 | [DllImport("PowrProf.dll")] 87 | public static extern 88 | uint PowerWriteDCValueIndex( 89 | IntPtr RootPowerKey, 90 | ref Guid SchemeGuid, 91 | ref Guid SubGroupOfPowerSettingsGuid, 92 | ref Guid PowerSettingGuid, 93 | uint DcValueIndex 94 | ); 95 | 96 | //http://msdn.microsoft.com/en-us/library/windows/desktop/aa372688(v=vs.85).aspx 97 | [DllImport("PowrProf.dll")] 98 | public static extern 99 | int GetActivePwrScheme(ref uint puiID); 100 | 101 | //http://msdn.microsoft.com/en-us/library/windows/desktop/aa372758(v=vs.85).aspx 102 | [DllImport("PowrProf.dll")] 103 | public static extern 104 | uint PowerSetActiveScheme(IntPtr UserRootPowerKey, ref Guid SchemeGuid); 105 | 106 | //http://msdn.microsoft.com/en-us/library/windows/desktop/aa372731(v=vs.85).aspx 107 | //DWORD WINAPI PowerGetActiveScheme( _In_opt_ HKEY UserRootPowerKey, _Out_ GUID **ActivePolicyGuid); 108 | [DllImport("PowrProf.dll")] 109 | public static extern 110 | uint PowerGetActiveScheme(IntPtr UserRootPowerKey, ref IntPtr p_ActivePolicyGuid); 111 | 112 | //http://msdn.microsoft.com/en-us/library/windows/desktop/aa373196(v=vs.85).aspx 113 | [DllImport(@"User32", SetLastError=true, EntryPoint = "RegisterPowerSettingNotification", 114 | CallingConvention = CallingConvention.StdCall)] 115 | public static extern 116 | IntPtr RegisterPowerSettingNotification( 117 | IntPtr hRecipient, 118 | ref Guid PowerSettingGuid, 119 | uint Flags 120 | ); 121 | public const uint DEVICE_NOTIFY_WINDOW_HANDLE = 0; 122 | public const uint DEVICE_NOTIFY_SERVICE_HANDLE = 1; 123 | //http://msdn.microsoft.com/en-us/library/windows/desktop/ms683241(v=vs.85).aspx 124 | public delegate uint HandlerEx( 125 | uint dwControl, uint dwEventType, IntPtr lpEventData, IntPtr lpContext); 126 | public const uint SERVICE_CONTROL_POWEREVENT = 0x0000000D; 127 | 128 | public const int WM_POWERBROADCAST = 0x218; 129 | public const int WM_QUERYENDSESSION = 0x011; 130 | public const int WM_ENDSESSION = 0X0016; 131 | //http://msdn.microsoft.com/en-us/library/windows/desktop/aa373237(v=vs.85).aspx 132 | [DllImport("User32.dll")] 133 | public static extern 134 | int UnregisterPowerSettingNotification(IntPtr Handle); 135 | 136 | [StructLayout(LayoutKind.Sequential, Pack = 4)] 137 | public struct POWERBROADCAST_SETTING 138 | { 139 | public Guid PowerSetting; 140 | public uint DataLength; 141 | public byte Data; 142 | } 143 | 144 | [DllImport("kernel32.dll")] 145 | public static extern IntPtr GetCurrentProcess(); 146 | 147 | [DllImport("kernel32.dll")] 148 | public static extern IntPtr GetCurrentThread(); 149 | 150 | //http://msdn.microsoft.com/en-us/library/windows/desktop/ms724251(v=vs.85).aspx 151 | [DllImport("kernel32.dll", SetLastError=true)] 152 | [return: MarshalAs(UnmanagedType.Bool)] 153 | public static extern bool DuplicateHandle(IntPtr hSourceProcessHandle, 154 | IntPtr hSourceHandle, IntPtr hTargetProcessHandle, ref IntPtr lpTargetHandle, 155 | uint dwDesiredAccess, [MarshalAs(UnmanagedType.Bool)] bool bInheritHandle, uint dwOptions); 156 | 157 | } 158 | } 159 | -------------------------------------------------------------------------------- /SleepPreventer/LocalString.resx: -------------------------------------------------------------------------------- 1 | 2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | text/microsoft-resx 110 | 111 | 112 | 2.0 113 | 114 | 115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | 118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 119 | 120 | 121 | Enable away mode 122 | 123 | 124 | Exit 125 | 126 | 127 | Awake when lid closed 128 | 129 | 130 | Monitor awake 131 | 132 | 133 | System awake 134 | 135 | 136 | SleepPreventer 137 | 138 | 139 | -------------------------------------------------------------------------------- /SleepPreventer/LocalString.zh-CN.resx: -------------------------------------------------------------------------------- 1 | 2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | text/microsoft-resx 110 | 111 | 112 | 2.0 113 | 114 | 115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | 118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 119 | 120 | 121 | 离开模式 122 | 123 | 124 | 退出 125 | 126 | 127 | 合上盖子时保持唤醒 128 | 129 | 130 | 保持显示器唤醒 131 | 132 | 133 | 保持系统唤醒 134 | 135 | 136 | 睡眠终结者 137 | 138 | 139 | 系统不支持该选项 140 | 141 | 142 | -------------------------------------------------------------------------------- /SleepPreventer/SleepPreventer.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {58ADD755-A57C-4B40-B1B2-1F3E697F03C2} 8 | WinExe 9 | Properties 10 | SleepPreventer 11 | SleepPreventer 12 | v3.5 13 | 512 14 | false 15 | 发布\ 16 | true 17 | Disk 18 | false 19 | Foreground 20 | 7 21 | Days 22 | false 23 | false 24 | true 25 | 0 26 | 1.0.0.%2a 27 | false 28 | true 29 | 30 | 31 | AnyCPU 32 | true 33 | full 34 | false 35 | bin\Debug\ 36 | DEBUG;TRACE 37 | prompt 38 | 4 39 | 40 | 41 | AnyCPU 42 | pdbonly 43 | true 44 | bin\Release\ 45 | TRACE 46 | prompt 47 | 4 48 | 49 | 50 | Resources\NoneSleep.ico 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | Form 66 | 67 | 68 | AboutBox.cs 69 | 70 | 71 | True 72 | True 73 | LocalString.resx 74 | 75 | 76 | 77 | Form 78 | 79 | 80 | MainForm.cs 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | AboutBox.cs 89 | 90 | 91 | ResXFileCodeGenerator 92 | LocalString.Designer.cs 93 | 94 | 95 | 96 | MainForm.cs 97 | Designer 98 | 99 | 100 | MainForm.cs 101 | 102 | 103 | ResXFileCodeGenerator 104 | Designer 105 | Resources.Designer.cs 106 | 107 | 108 | SettingsSingleFileGenerator 109 | Settings.Designer.cs 110 | 111 | 112 | True 113 | True 114 | Resources.resx 115 | 116 | 117 | True 118 | Settings.settings 119 | True 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | False 134 | .NET Framework 3.5 SP1 Client Profile 135 | false 136 | 137 | 138 | False 139 | .NET Framework 3.5 SP1 140 | true 141 | 142 | 143 | 144 | 145 | 146 | 147 | 154 | -------------------------------------------------------------------------------- /SleepPreventer/Properties/Resources.resx: -------------------------------------------------------------------------------- 1 | 2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | text/microsoft-resx 110 | 111 | 112 | 2.0 113 | 114 | 115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | 118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 119 | 120 | 121 | 122 | ..\Resources\NoneSleep.ico;System.Drawing.Icon, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a 123 | 124 | 125 | ..\Resources\PartSleep.ico;System.Drawing.Icon, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a 126 | 127 | 128 | ..\Resources\Allsleep.ico;System.Drawing.Icon, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a 129 | 130 | 131 | ..\Resources\sleep.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a 132 | 133 | 134 | Config 135 | 136 | -------------------------------------------------------------------------------- /SleepPreventer/OptionSetter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Runtime.InteropServices; 6 | using System.Windows.Forms; 7 | using Microsoft.Win32; 8 | using System.IO; 9 | 10 | namespace SleepPreventer 11 | { 12 | public class LidCloseAwakeKeeper : ValChangeEvent, IMessageFilter 13 | { 14 | public struct Setting 15 | { 16 | public bool Equals(Setting v) 17 | { 18 | // Return true if the fields match: 19 | return (v.ACIndex == this.ACIndex) && (v.DCIndex == this.DCIndex); 20 | } 21 | public uint DCIndex; 22 | public uint ACIndex; 23 | } 24 | 25 | public static bool GetActiveSchemeSetting( 26 | out Guid scheme_guid, ref Setting lid_close_setting) 27 | { 28 | if ( ! Public.PowerGetActiveSchemeWarp(out scheme_guid) ) 29 | { 30 | return false; 31 | } 32 | return GetSchemeSetting(scheme_guid, ref lid_close_setting); 33 | } 34 | 35 | public static bool GetSchemeSetting( 36 | Guid scheme_guid, ref Setting lid_close_setting) 37 | { 38 | uint index = 0; 39 | if( Win32API.PowerReadACValueIndex( 40 | IntPtr.Zero, 41 | ref scheme_guid, 42 | ref Public.GUID_SYSTEM_BUTTON_SUBGROUP, 43 | ref Public.GUID_LIDCLOSE_ACTION, 44 | ref index 45 | ) != 0) 46 | { 47 | return false; 48 | } 49 | lid_close_setting.ACIndex = index; 50 | 51 | if (Win32API.PowerReadDCValueIndex( 52 | IntPtr.Zero, 53 | ref scheme_guid, 54 | ref Public.GUID_SYSTEM_BUTTON_SUBGROUP, 55 | ref Public.GUID_LIDCLOSE_ACTION, 56 | ref index 57 | ) != 0) 58 | { 59 | return false; 60 | } 61 | lid_close_setting.DCIndex = index; 62 | 63 | return true; 64 | 65 | } 66 | 67 | public static bool WriteSchemeSetting( 68 | Guid scheme_guid, Setting lid_close_setting) 69 | { 70 | // Write setting 71 | if( Win32API.PowerWriteACValueIndex( 72 | IntPtr.Zero, 73 | ref scheme_guid, 74 | ref Public.GUID_SYSTEM_BUTTON_SUBGROUP, 75 | ref Public.GUID_LIDCLOSE_ACTION, 76 | lid_close_setting.ACIndex 77 | ) != 0) 78 | { 79 | return false; 80 | } 81 | 82 | if (Win32API.PowerWriteDCValueIndex( 83 | IntPtr.Zero, 84 | ref scheme_guid, 85 | ref Public.GUID_SYSTEM_BUTTON_SUBGROUP, 86 | ref Public.GUID_LIDCLOSE_ACTION, 87 | lid_close_setting.DCIndex 88 | ) != 0) 89 | { 90 | return false; 91 | } 92 | 93 | // Check is it current power scheme 94 | Guid cur_scheme; 95 | if (Public.PowerGetActiveSchemeWarp(out cur_scheme) ) 96 | { 97 | if (cur_scheme == scheme_guid) 98 | { 99 | if (Win32API.PowerSetActiveScheme( 100 | IntPtr.Zero, ref cur_scheme) != 0) 101 | { 102 | return false; 103 | } 104 | } 105 | } 106 | 107 | return true; 108 | } 109 | 110 | public static bool WriteActiveSchemeSetting(Setting lid_close_setting) 111 | { 112 | Guid scheme_guid; 113 | if ( ! Public.PowerGetActiveSchemeWarp(out scheme_guid) ) 114 | { 115 | return false; 116 | } 117 | return WriteSchemeSetting(scheme_guid, lid_close_setting); 118 | } 119 | 120 | public static void CheckLogError() 121 | { 122 | string fn = SleepPreventer.Properties.Resources.ConfigFileName; 123 | if (File.Exists(fn)) 124 | { 125 | using(var fs = File.OpenText(fn)) 126 | { 127 | string line = fs.ReadLine(); 128 | if (line == null) 129 | { 130 | // The file is empty 131 | return; 132 | } 133 | string[] s_ary = line.Split(' '); 134 | if (s_ary.Length == 2) 135 | { 136 | Setting back_st; 137 | back_st.ACIndex = uint.Parse(s_ary[0]); 138 | back_st.DCIndex = uint.Parse(s_ary[1]); 139 | 140 | // Get setting name 141 | Dictionary index_name = new Dictionary(); 142 | index_name[0] = "不采取任何操作"; 143 | index_name[1] = "睡眠"; 144 | index_name[2] = "休眠"; 145 | index_name[3] = "关机"; 146 | 147 | // Get current setting 148 | Guid guid; 149 | Setting cur_setting = new Setting(); 150 | if (!GetActiveSchemeSetting(out guid, ref cur_setting)) 151 | { 152 | return; 153 | } 154 | if (cur_setting.Equals(back_st)) 155 | { 156 | return; 157 | } 158 | 159 | string ac_setting, dc_setting; 160 | if (index_name.TryGetValue(back_st.ACIndex, out ac_setting) 161 | && index_name.TryGetValue(back_st.DCIndex, out dc_setting)) 162 | { 163 | if (MessageBox.Show("是否将合上盖子的操作恢复为: " 164 | + "\n\t" 165 | + "使用电池时:"+ ac_setting 166 | + "," 167 | + "使用外置电源时:" + dc_setting 168 | + "\n" 169 | + "当前的设置为: " 170 | + "\n\t" 171 | + "使用电池时:"+ index_name[cur_setting.ACIndex] 172 | + "," 173 | + "使用外置电源时:" + index_name[cur_setting.DCIndex], 174 | "本程序上次意外退出", 175 | MessageBoxButtons.OKCancel) == DialogResult.OK) 176 | { 177 | WriteActiveSchemeSetting(back_st); 178 | } 179 | } 180 | } 181 | } 182 | // Clean file 183 | using (StreamWriter sw = File.CreateText( 184 | SleepPreventer.Properties.Resources.ConfigFileName)) 185 | { 186 | ; 187 | } 188 | } 189 | } 190 | 191 | public LidCloseAwakeKeeper(IntPtr hWnd = default(IntPtr)) 192 | { 193 | hWnd_ = hWnd; 194 | if (hWnd_ == default(IntPtr)) 195 | { 196 | hWnd_ = IntPtr.Zero; 197 | } 198 | target_setting_ = new Setting(); 199 | target_setting_.ACIndex = target_power_setting_index_; 200 | target_setting_.DCIndex = target_power_setting_index_; 201 | 202 | lid_close_setting_back_ = new Setting(); 203 | GetActiveSchemeSetting(out scheme_guid_,ref lid_close_setting_back_); 204 | IsPrevent = false; 205 | is_watching_ = false; 206 | } 207 | 208 | ~LidCloseAwakeKeeper() 209 | { 210 | UnWatchPowerSetting(); 211 | } 212 | 213 | public bool IsPrevent { get; private set; } 214 | 215 | public bool TrySetNeedPrevent(bool value) 216 | { 217 | if (value != IsPrevent) 218 | { 219 | if (value) 220 | { 221 | if (WatchPowerSetting()) 222 | { 223 | IsPrevent = true; 224 | } 225 | } 226 | else 227 | { 228 | if (UnWatchPowerSetting()) 229 | { 230 | IsPrevent = false; 231 | } 232 | } 233 | RunValChangeCB(); 234 | return IsPrevent == value; 235 | } 236 | return true; 237 | } 238 | 239 | public bool PreFilterMessage(ref Message m) 240 | { 241 | if (is_watching_ ) 242 | { 243 | switch (m.Msg) 244 | { 245 | case Win32API.WM_POWERBROADCAST: 246 | DoWatchPowerSetting(); 247 | return true; 248 | case Win32API.WM_QUERYENDSESSION: 249 | this.TrySetNeedPrevent(false); 250 | return false; 251 | //case Win32API.WM_ENDSESSION: 252 | // return false; 253 | default: 254 | break; 255 | } 256 | } 257 | return false; 258 | } 259 | 260 | private bool DoWatchPowerSetting() 261 | { 262 | Guid cur_scheme_id; 263 | Setting setting = new Setting(); 264 | if (!GetActiveSchemeSetting(out cur_scheme_id, ref setting)) 265 | { 266 | return false; 267 | } 268 | 269 | // Check power setting value is changed 270 | if (setting.Equals(target_setting_)) 271 | { 272 | // Why the system send power setting changed message to me? 273 | return true; 274 | } 275 | 276 | if (scheme_guid_ != cur_scheme_id) 277 | { 278 | // The backup scheme is not active scheme now, write the backup setting back! 279 | WriteSchemeSetting(scheme_guid_, lid_close_setting_back_); 280 | } 281 | // Update the backup setting to current setting 282 | GetActiveSchemeSetting(out scheme_guid_, ref lid_close_setting_back_); 283 | // Write target Setting 284 | WriteSchemeSetting(cur_scheme_id, target_setting_); 285 | 286 | return true; 287 | } 288 | 289 | private bool WatchPowerSetting() 290 | { 291 | if (is_watching_) 292 | { 293 | return true; 294 | } 295 | // Backup current setting 296 | GetActiveSchemeSetting(out scheme_guid_, ref lid_close_setting_back_); 297 | 298 | // listen power setting changed event 299 | // Win32API.HandlerEx handler = this.SystemPowerSettingChangedHandle; 300 | // IntPtr p = handler.Method.MethodHandle.Value; 301 | //ps_changed_gc_h_ = GCHandle.Alloc(handler); 302 | 303 | //IntPtr p_phandle = Win32API.GetCurrentProcess(); 304 | //IntPtr t_phandle = Win32API.GetCurrentThread(); 305 | //IntPtr t_handle = IntPtr.Zero; 306 | //var error = Win32API.DuplicateHandle(p_phandle, t_phandle, p_phandle, ref t_handle, 0, false, 2); 307 | if (hWnd_ != IntPtr.Zero) 308 | { 309 | ps_changed_h_ = 310 | Win32API.RegisterPowerSettingNotification( 311 | //GCHandle.ToIntPtr(ps_changed_gc_h_), 312 | hWnd_, 313 | ref Public.GUID_LIDCLOSE_ACTION, 314 | Win32API.DEVICE_NOTIFY_WINDOW_HANDLE 315 | ); 316 | if (ps_changed_h_ != IntPtr.Zero) 317 | { 318 | // The form must call the message filter 319 | //Application.AddMessageFilter(this); 320 | } 321 | else 322 | { 323 | //ps_changed_gc_h_.Free(); 324 | return false; 325 | } 326 | } 327 | 328 | // Set target setting to system 329 | // The sheme_guid_ must be current scheme 330 | WriteSchemeSetting(scheme_guid_, target_setting_); 331 | // Write backup setting to file 332 | using (StreamWriter sw = File.CreateText(SleepPreventer.Properties.Resources.ConfigFileName)) 333 | { 334 | sw.WriteLine("" + 335 | lid_close_setting_back_.ACIndex + " " 336 | + lid_close_setting_back_.DCIndex ); 337 | } 338 | is_watching_ = true; 339 | return true; 340 | } 341 | 342 | private bool UnWatchPowerSetting() 343 | { 344 | if (! is_watching_) 345 | { 346 | return true; 347 | } 348 | bool result = true; // If need not to unregister, return true 349 | if (ps_changed_h_ != IntPtr.Zero) 350 | { 351 | result = (Win32API.UnregisterPowerSettingNotification(ps_changed_h_) != 0); 352 | //Application.RemoveMessageFilter(this); 353 | //ps_changed_gc_h_.Free(); 354 | } 355 | ps_changed_h_ = IntPtr.Zero; 356 | // Restore the backup setting 357 | WriteSchemeSetting(scheme_guid_, lid_close_setting_back_); 358 | // Clean back file 359 | using (StreamWriter sw = File.CreateText(SleepPreventer.Properties.Resources.ConfigFileName)) 360 | { 361 | ; 362 | } 363 | is_watching_ = false; 364 | return result; 365 | } 366 | 367 | 368 | private uint SystemPowerSettingChangedHandle( 369 | uint dwControl, uint dwEventType, IntPtr lpEventData, IntPtr lpContext) 370 | { 371 | MessageBox.Show("Power setting changed!"); 372 | if (dwControl == Win32API.SERVICE_CONTROL_POWEREVENT) 373 | { 374 | // TODO 375 | } 376 | return 0; 377 | } 378 | 379 | 380 | private IntPtr hWnd_; 381 | private IntPtr ps_changed_h_; 382 | //private GCHandle ps_changed_gc_h_; 383 | private Guid scheme_guid_; 384 | private Setting lid_close_setting_back_; 385 | private Setting target_setting_; 386 | private bool is_watching_; 387 | private const uint target_power_setting_index_ = Public.NO_ACTION_IN_LIDCLOSE_INDEX; 388 | } 389 | 390 | public class TExcState : ValChangeEvent 391 | { 392 | public const uint AWAY_MODE = Win32API.ES_AWAYMODE_REQUIRED; 393 | public const uint DISPLAY_REQ = Win32API.ES_DISPLAY_REQUIRED; 394 | public const uint SYS_REQ = Win32API.ES_SYSTEM_REQUIRED; 395 | // The ES_USER_PRESENT is invalid, reuse this magic number 396 | public const uint AWAKE_IN_LID_CLODE = Win32API.ES_USER_PRESENT; 397 | 398 | public TExcState(IntPtr hWnd = default(IntPtr)) 399 | { 400 | // Always Need this option 401 | cur_state_ = Win32API.ES_CONTINUOUS; 402 | lc_keeper_ = new LidCloseAwakeKeeper(hWnd); 403 | //lc_keeper_.AddValChangeCB(new ValChangeCB(this.RunValChangeCB)); 404 | } 405 | 406 | ~TExcState() 407 | { 408 | // The option will take effect before next set. 409 | Public.ResetSysIdle(Win32API.ES_CONTINUOUS); 410 | } 411 | 412 | public uint State 413 | { 414 | get { return cur_state_; } 415 | } 416 | 417 | public bool PreMessageFilter(ref Message m) 418 | { 419 | return lc_keeper_.PreFilterMessage(ref m); 420 | } 421 | 422 | public static uint SetBit(uint target, uint source, uint bits) 423 | { 424 | // reset target bits 425 | uint empty = target & ~bits; 426 | // set bits 427 | return empty | (source & bits); 428 | } 429 | 430 | 431 | public bool TrySetState(uint opt, bool setting) 432 | { 433 | uint opt_group = cur_state_; 434 | if (setting == true) 435 | { 436 | opt_group |= opt; 437 | } 438 | else 439 | { 440 | opt_group &= ~opt; 441 | } 442 | return TrySetStateGroup(opt_group); 443 | } 444 | 445 | private bool TrySetStateGroup(uint _state) 446 | { 447 | bool result = true; 448 | 449 | uint idle_state = _state & ~AWAKE_IN_LID_CLODE; 450 | // Handle SYS_REQ option 451 | // The DISPLAY_REQ option always need SYS_REQ option 452 | if ( (idle_state & DISPLAY_REQ) != 0) 453 | { 454 | idle_state |= SYS_REQ; 455 | } 456 | 457 | // Check sys idle state setter return 458 | if (Public.ResetSysIdle(idle_state)) 459 | { 460 | cur_state_ = SetBit(cur_state_, _state, 461 | AWAY_MODE | DISPLAY_REQ | SYS_REQ); 462 | } 463 | else 464 | { 465 | result = false; 466 | } 467 | 468 | // Check lid close power setting setter 469 | bool val = 470 | (_state & AWAKE_IN_LID_CLODE) != 0; 471 | if (!lc_keeper_.TrySetNeedPrevent(val)) 472 | { 473 | result = false; 474 | } 475 | uint bitmask = lc_keeper_.IsPrevent ? ~(uint)0 : (uint)0; 476 | cur_state_ = SetBit(cur_state_, bitmask, AWAKE_IN_LID_CLODE); 477 | RunValChangeCB(); 478 | return result; 479 | } 480 | private uint cur_state_; 481 | private LidCloseAwakeKeeper lc_keeper_; 482 | } 483 | 484 | } 485 | -------------------------------------------------------------------------------- /SleepPreventer/MainForm.zh-CN.resx: -------------------------------------------------------------------------------- 1 | 2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | text/microsoft-resx 110 | 111 | 112 | 2.0 113 | 114 | 115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | 118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 119 | 120 | 121 | 122 | 微软雅黑, 10.5pt 123 | 124 | 125 | 23, 23 126 | 127 | 128 | 129 | 3, 5, 3, 5 130 | 131 | 132 | 146, 24 133 | 134 | 135 | 微软雅黑, 10.5pt 136 | 137 | 138 | 23, 85 139 | 140 | 141 | 3, 5, 3, 5 142 | 143 | 144 | 112, 24 145 | 146 | 147 | 微软雅黑, 10.5pt 148 | 149 | 150 | 23, 54 151 | 152 | 153 | 3, 5, 3, 5 154 | 155 | 156 | 145, 24 157 | 158 | 159 | 微软雅黑, 10.5pt 160 | 161 | 162 | 28, 17 163 | 164 | 165 | 3, 5, 3, 5 166 | 167 | 168 | 3, 5, 3, 5 169 | 170 | 171 | 216, 120 172 | 173 | 174 | 通用: 175 | 176 | 177 | 微软雅黑, 10.5pt 178 | 179 | 180 | 156, 274 181 | 182 | 183 | 3, 5, 3, 5 184 | 185 | 186 | 87, 33 187 | 188 | 189 | 关于 190 | 191 | 192 | 微软雅黑, 10.5pt 193 | 194 | 195 | 23, 28 196 | 197 | 198 | 3, 5, 3, 5 199 | 200 | 201 | 194, 24 202 | 203 | 204 | 微软雅黑, 10.5pt 205 | 206 | 207 | 40, 52 208 | 209 | 210 | 136, 45 211 | 212 | 213 | 注意:这将修改系统电源设置 214 | 215 | 216 | 微软雅黑, 10.5pt 217 | 218 | 219 | 28, 145 220 | 221 | 222 | 3, 5, 3, 5 223 | 224 | 225 | 3, 5, 3, 5 226 | 227 | 228 | 216, 120 229 | 230 | 231 | 笔记本专用: 232 | 233 | 234 | 7, 17 235 | 236 | 237 | 270, 326 238 | 239 | 240 | 微软雅黑, 9pt 241 | 242 | 243 | 244 | AAABAAEAICAAAAEAIACoEAAAFgAAACgAAAAgAAAAQAAAAAEAIAAAAAAAAAAAAPAKAADwCgAAAAAAAAAA 245 | AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 246 | AAALALkICwC5CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 247 | AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAALAMAIKR7Bdh8W 248 | vsYSBr3zDQC+/w0AwP8NAMD/DQC+/xMHvPAfFL68GA2+YQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 249 | AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMAL4WIxq/vAsA 250 | v/8MAMv/DQDT/w4A1P8NANT/DQDU/w0A1P8NANT/DADT/w0A0/8NAMr/DQC9/x0UvqQLAL8KAAAAAAAA 251 | AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAKB3CjAwA 252 | wP8NANL/DADV/w0A1P8NANT/DADU/wwA1P8MANT/DADU/wwA1P8NANT/DQDU/w0A1P8MANX/DwDQ/woA 253 | v/8XDsBqAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAB0S 254 | v9QNAMz/DQDX/w0A1f8NANX/DQDV/w0A1f8NANX/DQDV/w0A1v8NANb/DQDV/w0A1f8NANX/DQDV/w0A 255 | 1f8NANX/DgDW/w4Ayf8fFL+8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 256 | AAAXDL7mDQDT/w4A1v8PANX/DwDV/w4A1v8NANf/DgDW/w0A0P8MAMr/DwDE/w8AxP8NAMn/DgDN/w4A 257 | 1v8NANf/DgDW/w8A1f8OANb/DQDX/w0Az/8cEcDTAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 258 | AP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/9HP 259 | 9L6WkOPOQjrN6A4Aw/8LANb/DgDY/w8A1/8PANf/DgDY/w0A0v8eFcO6AAAAAAAAAAAAAAAAAAAAAAAA 260 | AAAAAAAAAAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAA 261 | AP8AAAD/////s////7P///+z9fT8tTsxyuwNANf/DgDa/w4A2v8OANr/DgDb/wsAzv8bD8ZmAAAAAAAA 262 | AAAAAAAAAAAAAAAAAAAAAAD/AAAA/wAAAP8AAAD/AAAA/wIAG/8MAM//Z2DY3P///7P///+z////s/// 263 | /7P///+z////s////7P///+z////s////7PW1PW9FQjE+w0A2/8PANr/DwDa/w8A2v8PANr/DgDc/wsA 264 | xf8OAMcGAAAAAAAAAAAAAAAAAAAAAA8Jb9gAAAD/AAAA/wAAAP8AAAD/AQAM/1NNrOL///+z////s/// 265 | /7P///+z////s////7P///+z////s////7P///+zyMXywAsAx/8QAN7/DwDd/w8A3f8OAN7/DwDd/w8A 266 | 3P8PAN3/DgDa/x8VyJ4AAAAAAAAAAAAAAAAOAM0SDADN/wUAU/8AAAD/AAAA/wAAAP8AAAD/IyMj8enp 267 | 6bj///+z////s////7P///+z////s////7P///+z////s7u48MMMAMr/DwDf/w8A3/8PAN//DgDe/wwA 268 | y/8OANr/DwDf/xAA3v8QAN//DQDL/wAAAAAAAAAAAAAAAC0hzoUOANv/DwDh/wYAVP8AAAD/AAAA/wAA 269 | AP8AAAD/IyMj8enp6bj///+z////s////7P///+z////s////7Ouqu3HDgDN/w4A4f8PAOH/DwDh/w4A 270 | 3v8hFsz28vH8thQHyvwPAOL/DwDh/w8A4f8OANf/FwzMVgAAAAAAAAAAHhPN1Q8A5P8PAOL/DwDi/wYA 271 | VP8AAAD/AAAA/wAAAP8AAAD/IyMj8enp6bj///+z////s////7P///+zop3ryg4Az/8RAOT/DgDj/w4A 272 | 4/8OAOD/KBzN9P///7P///+zdG3g2A8A3f8OAOP/DwDi/w4A4/8jF86zAAAAAAAAAAAMAdL+DQDm/w8A 273 | 5P8OAOX/CwDd/zEwTOwAAAD/AAAA/wAAAP8AAAD/IyMj8enp6bj///+z////s5KN6c4OANL/DwDm/wAA 274 | AP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/xkMz+gAAAAADQDQCA4A 275 | 1v8OAOj/DgDn/w4A5/8PANb/z87lviMjI/EAAAD/AAAA/wAAAP8AAAD/S0tL4////7OGf+bTDwDW/w4A 276 | 6P8OAOf/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/DADT/wAA 277 | AAAOANAWDgDb/w4A6v8OAOj/DgDq/w0A1v////+z6enpuCMjI/EAAAD/AAAA/wAAAP8AAAD/KCZM8A8A 278 | 2/8OAOv/DQDp/w4A6v8CACr/AAAA/wAAAP8AAAD/IyMj8f///7P///+z////syYZ1vUNAOv/DgDo/w4A 279 | 6v8OANb/AAAAAA0A0xYOANz/EADr/xAA6v8PAOz/DQDY/////7P///+z6enpuCMjI/EAAAD/AAAA/wAA 280 | AP8AAAD/BgBY/xAA6v8RAOz/DgDj/0I6vugLCwv7AAAA/wAAAP8AAAD/eHh41P///7P///+zKx/X8hEA 281 | 7P8QAOr/DwDs/w8A2P8AAAAADQDVCA4A3P8PAO7/EQDs/w8A7v8QANv/8vH9tv///7P///+z6enpuCMj 282 | I/EAAAD/AAAA/wAAAP8AAAD/BgBZ/w0A5P9YT+Dh////s8DAwMELCwv7AAAA/wAAAP8AAAD/iYmJ0P// 283 | /7MYC9j6DwDu/xEA7P8PAO7/DgDZ/wAAAAAAAAAAEAHa/g4A8f8PAPD/DwDw/w0A5f+4tPTE////s/// 284 | /7P///+zTkXf5QEADv8AAAD/AAAA/wAAAP8AAAD/OzaG6v///7P///+z////s8DAwMELCwv7AAAA/wAA 285 | AP8AAAD/g4KJ0Q8A3/8OAPH/DwDw/w8A8f8ZDNroAAAAAAAAAAAWCNnJEADy/w8A8v8PAPL/DgDv/2Nb 286 | 5t7///+z////s0M54OkPAOn/AgAe/wAAAP8AAAD/AAAA/wAAAP8AAAD/////s////7P///+z////s62t 287 | rcYAAAD/AAAA/wAAAP8AAAD/CgCu/w8A8v8PAPL/DwDx/yQX3LMAAAAAAAAAAA4A2nQAAAD/AAAA/wAA 288 | AP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP////+z////s/// 289 | /7P///+z////s4mJidAAAAD/AAAA/wAAAP8BAA7/DQDE/w8A8/8PAOr/GgzfWAAAAAAAAAAAEADhEgAA 290 | AP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA//// 291 | /7P///+z////s////7P///+z////s4mJidAAAAD/AAAA/wAAAP8BAA7/DADJ/w8A3/8AAAAAAAAAAAAA 292 | AAAAAAAAEwbetRAA9v8PAPj/DwD4/w8A+P8OAPn/DwD4/w8A+P8PAPj/DwDk/52Y8sv///+z////s/// 293 | /7P///+z////s////7P///+z////s////7P///+z9fT+tQsCfv4AAAD/AAAA/wAAAP8BAA7/HBK3qwAA 294 | AAAAAAAAAAAAAAAAAAANAOQaDgDl/w8A+/8PAPj/DwD4/w8A+P8PAPj/DwD6/w0A5f+tqPXH////s/// 295 | /7P///+z////s////7P///+z////s////7P///+z////s/X0/rUgEd/4DwD4/wMALv8AAAD/AAAA/wAA 296 | AP8AAAD/AAAAAAAAAAAAAAAAAAAAAAAAAAAPAOCBDwDz/xAA+/8RAPr/EQD6/xAA+/8PAPj/Vkzp4v// 297 | /7P///+z////s////7P///+z////s////7MAAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAA 298 | AP8AAAD/AAAA/wAAAP8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAVB+PNEAD6/w8A/f8PAP3/DwD9/xEA 299 | +/8PAPP/JRnm9ZSN8875+f+0////s////7P///+z////swAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAA 300 | AP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAUB+XhEQD7/xAA 301 | /v8QAP7/EAD+/xAA/v8RAP7/EAD2/xEA7P8fE+j3OCzq7jwv6u0mGun0DgDr/xEA8/8QAP7/EAD+/xAA 302 | /v8QAP7/DwD//w8A+P8gE+XTAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 303 | AAAXCOXLEAD2/xIC//8RAP//EQD+/xEA//8RAP//EQH//xEB//8RAf//EQH//xEB//8RAf//EQD//xEA 304 | //8RAP//EQD//xIC//8PAPX/JRfmvgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 305 | AAAAAAAAAAAAAAAAAAARAuZ5EADt/xEB//8UA///EwL//xMC//8TAv//EwL//xMC//8TAv//EwL//xMC 306 | //8TAv//EwL//xQC//8OAP//DgDs/yAR6mkAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 307 | AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAO0UEgTorA4A7/8QAPr/FAP//xME//8UBP//FAT//xQE 308 | //8UBP//EwP//xQD//8QAPr/EADt/yUY6qsPAO4KAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 309 | AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADgDvChAA6mgVBuq5FQXr8g8A 310 | 8f8QAPL/EADy/xAA8P8ZCuzwJRfrvh0P7WQOAO8CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 311 | AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 312 | AAAAAAAAAAAAABAA7QoQAO0KAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 313 | AAAAAAAAAAAAAAAAAAAAAAAA//5////AB///AAD//gAAf/wAAD/4AAAfwAAAD8AAAAfAAAADwAAAA4AA 314 | AAOAAAABgAAAAYAAAAEAAAABAAAAAQAAAAEAAAABgAAAAYAAAAGAAAABgAAAA8AAAAPAAAAD4AAAA/AA 315 | AAP4AAAf/AAAP/4AAH//AAD//8AD///+f/8= 316 | 317 | 318 | 319 | 3, 5, 3, 5 320 | 321 | -------------------------------------------------------------------------------- /SleepPreventer/MainForm.resx: -------------------------------------------------------------------------------- 1 | 2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | text/microsoft-resx 110 | 111 | 112 | 2.0 113 | 114 | 115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | 118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 119 | 120 | 121 | groupBox1 122 | 123 | 124 | Note: will modify system power setting. 125 | 126 | 127 | 2 128 | 129 | 130 | 131 | Times New Roman, 10.5pt 132 | 133 | 134 | 135 | 3, 4, 3, 4 136 | 137 | 138 | 139 | 0 140 | 141 | 142 | 2 143 | 144 | 145 | 3, 4, 3, 4 146 | 147 | 148 | $this 149 | 150 | 151 | PH_SYS_REQ 152 | 153 | 154 | System.Windows.Forms.GroupBox, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 155 | 156 | 157 | System.Windows.Forms.CheckBox, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 158 | 159 | 160 | True 161 | 162 | 163 | About 164 | 165 | 166 | 169, 32 167 | 168 | 169 | label1 170 | 171 | 172 | 134, 20 173 | 174 | 175 | 23, 75 176 | 177 | 178 | Times New Roman, 10.5pt 179 | 180 | 181 | True 182 | 183 | 184 | 7, 15 185 | 186 | 187 | groupBox2 188 | 189 | 190 | Times New Roman, 10.5pt 191 | 192 | 193 | 0 194 | 195 | 196 | PH_DISPLAY_REQ 197 | 198 | 199 | Times New Roman, 10.5pt 200 | 201 | 202 | PH_AWAY_MODE 203 | 204 | 205 | CenterScreen 206 | 207 | 208 | groupBox2 209 | 210 | 211 | 0 212 | 213 | 214 | Common: 215 | 216 | 217 | System.Windows.Forms.CheckBox, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 218 | 219 | 220 | 87, 29 221 | 222 | 223 | 5 224 | 225 | 226 | 23, 48 227 | 228 | 229 | checkBox1 230 | 231 | 232 | 3, 4, 3, 4 233 | 234 | 235 | 3, 4, 3, 4 236 | 237 | 238 | 23, 25 239 | 240 | 241 | True 242 | 243 | 244 | Times New Roman, 10.5pt 245 | 246 | 247 | 156, 242 248 | 249 | 250 | System.Windows.Forms.Button, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 251 | 252 | 253 | 28, 128 254 | 255 | 256 | 1 257 | 258 | 259 | 1 260 | 261 | 262 | 23, 20 263 | 264 | 265 | Times New Roman, 9pt 266 | 267 | 268 | 0 269 | 270 | 271 | 3, 4, 3, 4 272 | 273 | 274 | 3, 4, 3, 4 275 | 276 | 277 | 4 278 | 279 | 280 | 189, 20 281 | 282 | 283 | 3, 4, 3, 4 284 | 285 | 286 | groupBox1 287 | 288 | 289 | $this 290 | 291 | 292 | 28, 15 293 | 294 | 295 | True 296 | 297 | 298 | Times New Roman, 10.5pt 299 | 300 | 301 | 216, 106 302 | 303 | 304 | System.Windows.Forms.CheckBox, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 305 | 306 | 307 | 3 308 | 309 | 310 | button1 311 | 312 | 313 | checkBox3 314 | 315 | 316 | 0 317 | 318 | 319 | PH_AWAY_IN_LID_CLOSE 320 | 321 | 322 | Times New Roman, 10.5pt 323 | 324 | 325 | 326 | AAABAAEAICAAAAEAIACoEAAAFgAAACgAAAAgAAAAQAAAAAEAIAAAAAAAAAAAAPAKAADwCgAAAAAAAAAA 327 | AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 328 | AAALALkICwC5CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 329 | AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAALAMAIKR7Bdh8W 330 | vsYSBr3zDQC+/w0AwP8NAMD/DQC+/xMHvPAfFL68GA2+YQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 331 | AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMAL4WIxq/vAsA 332 | v/8MAMv/DQDT/w4A1P8NANT/DQDU/w0A1P8NANT/DADT/w0A0/8NAMr/DQC9/x0UvqQLAL8KAAAAAAAA 333 | AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAKB3CjAwA 334 | wP8NANL/DADV/w0A1P8NANT/DADU/wwA1P8MANT/DADU/wwA1P8NANT/DQDU/w0A1P8MANX/DwDQ/woA 335 | v/8XDsBqAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAB0S 336 | v9QNAMz/DQDX/w0A1f8NANX/DQDV/w0A1f8NANX/DQDV/w0A1v8NANb/DQDV/w0A1f8NANX/DQDV/w0A 337 | 1f8NANX/DgDW/w4Ayf8fFL+8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 338 | AAAXDL7mDQDT/w4A1v8PANX/DwDV/w4A1v8NANf/DgDW/w0A0P8MAMr/DwDE/w8AxP8NAMn/DgDN/w4A 339 | 1v8NANf/DgDW/w8A1f8OANb/DQDX/w0Az/8cEcDTAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 340 | AP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/9HP 341 | 9L6WkOPOQjrN6A4Aw/8LANb/DgDY/w8A1/8PANf/DgDY/w0A0v8eFcO6AAAAAAAAAAAAAAAAAAAAAAAA 342 | AAAAAAAAAAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAA 343 | AP8AAAD/////s////7P///+z9fT8tTsxyuwNANf/DgDa/w4A2v8OANr/DgDb/wsAzv8bD8ZmAAAAAAAA 344 | AAAAAAAAAAAAAAAAAAAAAAD/AAAA/wAAAP8AAAD/AAAA/wIAG/8MAM//Z2DY3P///7P///+z////s/// 345 | /7P///+z////s////7P///+z////s////7PW1PW9FQjE+w0A2/8PANr/DwDa/w8A2v8PANr/DgDc/wsA 346 | xf8OAMcGAAAAAAAAAAAAAAAAAAAAAA8Jb9gAAAD/AAAA/wAAAP8AAAD/AQAM/1NNrOL///+z////s/// 347 | /7P///+z////s////7P///+z////s////7P///+zyMXywAsAx/8QAN7/DwDd/w8A3f8OAN7/DwDd/w8A 348 | 3P8PAN3/DgDa/x8VyJ4AAAAAAAAAAAAAAAAOAM0SDADN/wUAU/8AAAD/AAAA/wAAAP8AAAD/IyMj8enp 349 | 6bj///+z////s////7P///+z////s////7P///+z////s7u48MMMAMr/DwDf/w8A3/8PAN//DgDe/wwA 350 | y/8OANr/DwDf/xAA3v8QAN//DQDL/wAAAAAAAAAAAAAAAC0hzoUOANv/DwDh/wYAVP8AAAD/AAAA/wAA 351 | AP8AAAD/IyMj8enp6bj///+z////s////7P///+z////s////7Ouqu3HDgDN/w4A4f8PAOH/DwDh/w4A 352 | 3v8hFsz28vH8thQHyvwPAOL/DwDh/w8A4f8OANf/FwzMVgAAAAAAAAAAHhPN1Q8A5P8PAOL/DwDi/wYA 353 | VP8AAAD/AAAA/wAAAP8AAAD/IyMj8enp6bj///+z////s////7P///+zop3ryg4Az/8RAOT/DgDj/w4A 354 | 4/8OAOD/KBzN9P///7P///+zdG3g2A8A3f8OAOP/DwDi/w4A4/8jF86zAAAAAAAAAAAMAdL+DQDm/w8A 355 | 5P8OAOX/CwDd/zEwTOwAAAD/AAAA/wAAAP8AAAD/IyMj8enp6bj///+z////s5KN6c4OANL/DwDm/wAA 356 | AP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/xkMz+gAAAAADQDQCA4A 357 | 1v8OAOj/DgDn/w4A5/8PANb/z87lviMjI/EAAAD/AAAA/wAAAP8AAAD/S0tL4////7OGf+bTDwDW/w4A 358 | 6P8OAOf/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/DADT/wAA 359 | AAAOANAWDgDb/w4A6v8OAOj/DgDq/w0A1v////+z6enpuCMjI/EAAAD/AAAA/wAAAP8AAAD/KCZM8A8A 360 | 2/8OAOv/DQDp/w4A6v8CACr/AAAA/wAAAP8AAAD/IyMj8f///7P///+z////syYZ1vUNAOv/DgDo/w4A 361 | 6v8OANb/AAAAAA0A0xYOANz/EADr/xAA6v8PAOz/DQDY/////7P///+z6enpuCMjI/EAAAD/AAAA/wAA 362 | AP8AAAD/BgBY/xAA6v8RAOz/DgDj/0I6vugLCwv7AAAA/wAAAP8AAAD/eHh41P///7P///+zKx/X8hEA 363 | 7P8QAOr/DwDs/w8A2P8AAAAADQDVCA4A3P8PAO7/EQDs/w8A7v8QANv/8vH9tv///7P///+z6enpuCMj 364 | I/EAAAD/AAAA/wAAAP8AAAD/BgBZ/w0A5P9YT+Dh////s8DAwMELCwv7AAAA/wAAAP8AAAD/iYmJ0P// 365 | /7MYC9j6DwDu/xEA7P8PAO7/DgDZ/wAAAAAAAAAAEAHa/g4A8f8PAPD/DwDw/w0A5f+4tPTE////s/// 366 | /7P///+zTkXf5QEADv8AAAD/AAAA/wAAAP8AAAD/OzaG6v///7P///+z////s8DAwMELCwv7AAAA/wAA 367 | AP8AAAD/g4KJ0Q8A3/8OAPH/DwDw/w8A8f8ZDNroAAAAAAAAAAAWCNnJEADy/w8A8v8PAPL/DgDv/2Nb 368 | 5t7///+z////s0M54OkPAOn/AgAe/wAAAP8AAAD/AAAA/wAAAP8AAAD/////s////7P///+z////s62t 369 | rcYAAAD/AAAA/wAAAP8AAAD/CgCu/w8A8v8PAPL/DwDx/yQX3LMAAAAAAAAAAA4A2nQAAAD/AAAA/wAA 370 | AP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP////+z////s/// 371 | /7P///+z////s4mJidAAAAD/AAAA/wAAAP8BAA7/DQDE/w8A8/8PAOr/GgzfWAAAAAAAAAAAEADhEgAA 372 | AP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA//// 373 | /7P///+z////s////7P///+z////s4mJidAAAAD/AAAA/wAAAP8BAA7/DADJ/w8A3/8AAAAAAAAAAAAA 374 | AAAAAAAAEwbetRAA9v8PAPj/DwD4/w8A+P8OAPn/DwD4/w8A+P8PAPj/DwDk/52Y8sv///+z////s/// 375 | /7P///+z////s////7P///+z////s////7P///+z9fT+tQsCfv4AAAD/AAAA/wAAAP8BAA7/HBK3qwAA 376 | AAAAAAAAAAAAAAAAAAANAOQaDgDl/w8A+/8PAPj/DwD4/w8A+P8PAPj/DwD6/w0A5f+tqPXH////s/// 377 | /7P///+z////s////7P///+z////s////7P///+z////s/X0/rUgEd/4DwD4/wMALv8AAAD/AAAA/wAA 378 | AP8AAAD/AAAAAAAAAAAAAAAAAAAAAAAAAAAPAOCBDwDz/xAA+/8RAPr/EQD6/xAA+/8PAPj/Vkzp4v// 379 | /7P///+z////s////7P///+z////s////7MAAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAA 380 | AP8AAAD/AAAA/wAAAP8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAVB+PNEAD6/w8A/f8PAP3/DwD9/xEA 381 | +/8PAPP/JRnm9ZSN8875+f+0////s////7P///+z////swAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAA 382 | AP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAUB+XhEQD7/xAA 383 | /v8QAP7/EAD+/xAA/v8RAP7/EAD2/xEA7P8fE+j3OCzq7jwv6u0mGun0DgDr/xEA8/8QAP7/EAD+/xAA 384 | /v8QAP7/DwD//w8A+P8gE+XTAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 385 | AAAXCOXLEAD2/xIC//8RAP//EQD+/xEA//8RAP//EQH//xEB//8RAf//EQH//xEB//8RAf//EQD//xEA 386 | //8RAP//EQD//xIC//8PAPX/JRfmvgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 387 | AAAAAAAAAAAAAAAAAAARAuZ5EADt/xEB//8UA///EwL//xMC//8TAv//EwL//xMC//8TAv//EwL//xMC 388 | //8TAv//EwL//xQC//8OAP//DgDs/yAR6mkAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 389 | AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAO0UEgTorA4A7/8QAPr/FAP//xME//8UBP//FAT//xQE 390 | //8UBP//EwP//xQD//8QAPr/EADt/yUY6qsPAO4KAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 391 | AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADgDvChAA6mgVBuq5FQXr8g8A 392 | 8f8QAPL/EADy/xAA8P8ZCuzwJRfrvh0P7WQOAO8CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 393 | AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 394 | AAAAAAAAAAAAABAA7QoQAO0KAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 395 | AAAAAAAAAAAAAAAAAAAAAAAA//5////AB///AAD//gAAf/wAAD/4AAAfwAAAD8AAAAfAAAADwAAAA4AA 396 | AAOAAAABgAAAAYAAAAEAAAABAAAAAQAAAAEAAAABgAAAAYAAAAGAAAABgAAAA8AAAAPAAAAD4AAAA/AA 397 | AAP4AAAf/AAAP/4AAH//AAD//8AD///+f/8= 398 | 399 | 400 | 401 | System.Windows.Forms.GroupBox, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 402 | 403 | 404 | System.Windows.Forms.Form, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 405 | 406 | 407 | 3, 4, 3, 4 408 | 409 | 410 | checkBox2 411 | 412 | 413 | 40, 46 414 | 415 | 416 | 216, 106 417 | 418 | 419 | checkBox4 420 | 421 | 422 | groupBox1 423 | 424 | 425 | 1 426 | 427 | 428 | groupBox2 429 | 430 | 431 | Laptop Only: 432 | 433 | 434 | 5 435 | 436 | 437 | 3, 4, 3, 4 438 | 439 | 440 | Times New Roman, 10.5pt 441 | 442 | 443 | PH_TITLE 444 | 445 | 446 | groupBox1 447 | 448 | 449 | 110, 20 450 | 451 | 452 | System.Windows.Forms.CheckBox, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 453 | 454 | 455 | 270, 288 456 | 457 | 458 | 1 459 | 460 | 461 | MainForm 462 | 463 | 464 | 3, 4, 3, 4 465 | 466 | 467 | 0 468 | 469 | 470 | $this 471 | 472 | 473 | System.Windows.Forms.Label, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 474 | 475 | 476 | 141, 20 477 | 478 | 479 | True 480 | 481 | 482 | zh-CN 483 | 484 | --------------------------------------------------------------------------------