分享一个WPF 实现 Windows 软件快捷小工具
原创
©著作权归作者所有:来自51CTO博客作者biyusr216的原创作品,请联系作者获取转载授权,否则将追究法律责任
分享一个WPF 实现 Windows 软件快捷小工具
Windows 软件快捷小工具
作者:WPFDevelopersOrg
- 框架使用
.NET40
; -
Visual Studio 2019
; - 项目使用 MIT 开源许可协议;
- 项目使用
MVVM
模式来实现详细学习和理解 WPF
; - 项目中技术使用到
WindowsAPI
、Style
、CustomControl
、Json 序列化和反序列化
、换肤 Dark|Light
、动画
、Hook 按键与鼠标
、颜色拾取
、截屏
、DPI缩放
、开机启动
、NLog
、转换器
、禁止程序多开并唤醒之前程序
等; - 欢迎下载项目进行魔改;
- 更多效果可以通过GitHub[1]|码云[2]下载代码;
预览
启动页
![分享一个WPF 实现 Windows 软件快捷小工具_github](https://s2.51cto.com/images/blog/202207/23055810_62db1d720a08090414.gif)
嵌入桌面
![分享一个WPF 实现 Windows 软件快捷小工具_github_02](https://s2.51cto.com/images/blog/202207/23055810_62db1d726b17764002.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_30,g_se,x_10,y_10,shadow_20,type_ZmFuZ3poZW5naGVpdGk=/resize,m_fixed,w_1184)
悬浮桌面
![分享一个WPF 实现 Windows 软件快捷小工具_ico_03](https://s2.51cto.com/images/blog/202207/23055810_62db1d729333c4380.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_30,g_se,x_10,y_10,shadow_20,type_ZmFuZ3poZW5naGVpdGk=/resize,m_fixed,w_1184)
颜色拾取
![分享一个WPF 实现 Windows 软件快捷小工具_git_04](https://s2.51cto.com/images/blog/202207/23055811_62db1d73040f195613.gif)
预览原文
启动页
![分享一个WPF 实现 Windows 软件快捷小工具_github_05](https://s2.51cto.com/images/blog/202207/23055811_62db1d73d4fae15631.gif)
![分享一个WPF 实现 Windows 软件快捷小工具_windows_06](https://s2.51cto.com/images/blog/202207/23055812_62db1d747ca8475805.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_30,g_se,x_10,y_10,shadow_20,type_ZmFuZ3poZW5naGVpdGk=/resize,m_fixed,w_1184)
搜索定位功能 LeftAlt+(应用首字的首字母)
![分享一个WPF 实现 Windows 软件快捷小工具_wpf_07](https://s2.51cto.com/images/blog/202207/23055812_62db1d74efe187316.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_30,g_se,x_10,y_10,shadow_20,type_ZmFuZ3poZW5naGVpdGk=/resize,m_fixed,w_1184)
托盘、换肤、透明度
![分享一个WPF 实现 Windows 软件快捷小工具_ico_08](https://s2.51cto.com/images/blog/202207/23055813_62db1d757f9a468003.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_30,g_se,x_10,y_10,shadow_20,type_ZmFuZ3poZW5naGVpdGk=/resize,m_fixed,w_1184)
移动应用顺序
![分享一个WPF 实现 Windows 软件快捷小工具_github_09](https://s2.51cto.com/images/blog/202207/23055813_62db1d75c4c7f8338.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_30,g_se,x_10,y_10,shadow_20,type_ZmFuZ3poZW5naGVpdGk=/resize,m_fixed,w_1184)
移除应用
![分享一个WPF 实现 Windows 软件快捷小工具_windows_10](https://s2.51cto.com/images/blog/202207/23055814_62db1d762204b46093.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_30,g_se,x_10,y_10,shadow_20,type_ZmFuZ3poZW5naGVpdGk=/resize,m_fixed,w_1184)
自动更新(失效)
1)开机启动
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
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;
}
}
}
WPF开发者
,赞 20
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