分享一个WPF 实现 Windows 软件快捷小工具
Windows 软件快捷小工具 作者:WPFDevelopersOrg 原文链接:https://github.com/WPFDevelopersOrg/SoftwareHelper
- 框架使用
.NET40
; Visual Studio 2019
;- 项目使用 MIT 开源许可协议;
- 项目使用
MVVM
模式来实现详细学习和理解WPF
; - 项目中技术使用到
WindowsAPI
、Style
、CustomControl
、Json 序列化和反序列化
、换肤 Dark|Light
、动画
、Hook 按键与鼠标
、颜色拾取
、截屏
、DPI缩放
、开机启动
、NLog
、转换器
、禁止程序多开并唤醒之前程序
等; - 欢迎下载项目进行魔改;
- 更多效果可以通过GitHub[1]|码云[2]下载代码;
预览
启动页
嵌入桌面
悬浮桌面
颜色拾取
预览原文
启动页
搜索定位功能 LeftAlt (应用首字的首字母)
托盘、换肤、透明度
移动应用顺序
移除应用
自动更新(失效)
1)开机启动
代码语言:javascript复制 private void appShortcutToStartup()
{
var startupDir = Environment.GetFolderPath(Environment.SpecialFolder.Startup);
if (!Directory.Exists(startupDir)) return;
var path = startupDir "\" "SoftwareHelperStart" ".url";
if (!File.Exists(path))
using (var writer = new StreamWriter(path))
{
var app = Assembly.GetExecutingAssembly().Location;
writer.WriteLine("[InternetShortcut]");
writer.WriteLine("URL=file:///" app);
writer.WriteLine("IconIndex=0");
var icon = app.Replace('\', '/');
writer.WriteLine("IconFile=" icon);
}
}
}
2) 换肤 Dark|Light
代码语言:javascript复制using System;
using System.Configuration;
using System.Linq;
using System.Windows;
namespace SoftwareHelper.Helpers
{
/// <summary>
/// Themes 帮助类
/// </summary>
public partial class ThemesHelper
{
/// <summary>
/// 切换Themes
/// </summary>
/// <param name="isDark">true:Dark false:light</param>
public static void SetLightDark(bool isDark)
{
try
{
var existingResourceDictionary = Application.Current.Resources.MergedDictionaries
.Where(rd => rd.Source != null)
.SingleOrDefault(rd => rd.Source.OriginalString.Contains("Light") || rd.Source.OriginalString.Contains("Dark"));
var source = $"pack://application:,,,/SoftwareHelper;component/Themes/{(isDark ? "Dark" : "Light")}.xaml";
var newResourceDictionary = new ResourceDictionary() { Source = new Uri(source) };
App.Current.Resources.MergedDictionaries.Remove(existingResourceDictionary);
App.Current.Resources.MergedDictionaries.Add(newResourceDictionary);
//节点
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
config.AppSettings.Settings["Dark"].Value = isDark.ToString();
config.Save(ConfigurationSaveMode.Modified);
ConfigurationManager.RefreshSection("appSettings");
}
catch (Exception ex)
{
Log.Error($"MainView.SetLightDark Error:{ex.Message}");
}
}
public static bool GetLightDark()
{
bool dark;
if (!bool.TryParse(string.IsNullOrWhiteSpace(ConfigurationManager.AppSettings["Dark"]) ? "false" : ConfigurationManager.AppSettings["Dark"], out dark))
{
dark = false;
}
else
{
dark = Convert.ToBoolean(string.IsNullOrWhiteSpace(ConfigurationManager.AppSettings["Dark"]) ? "false" : ConfigurationManager.AppSettings["Dark"]);
}
return dark;
}
}
}
Hook 按键[3]Hook 鼠标[4]颜色拾取[5]
参考资料
[1]GitHub: https://github.com/WPFDevelopersOrg/SoftwareHelper
[2]码云: https://gitee.com/WPFDevelopersOrg/SoftwareHelper
[3]Hook 按键: https://gitee.com/WPFDevelopersOrg/SoftwareHelper/blob/master/SoftwareHelper/Helpers/KeyboardHook.cs
[4]Hook 鼠标: https://gitee.com/WPFDevelopersOrg/SoftwareHelper/blob/master/SoftwareHelper/Helpers/MouseHelper/MouseHook.cs
[5]颜色拾取: https://gitee.com/WPFDevelopersOrg/SoftwareHelper/blob/master/SoftwareHelper/Views/WindowColor.xaml