前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >分享一个WPF 实现 Windows 软件快捷小工具

分享一个WPF 实现 Windows 软件快捷小工具

作者头像
独立观察员
发布2022-12-06 19:23:40
3660
发布2022-12-06 19:23:40
举报

分享一个WPF 实现 Windows 软件快捷小工具

Windows 软件快捷小工具 作者:WPFDevelopersOrg 原文链接:https://github.com/WPFDevelopersOrg/SoftwareHelper

  • 框架使用.NET40
  • Visual Studio 2019;
  • 项目使用 MIT 开源许可协议;
  • 项目使用 MVVM 模式来实现详细学习和理解 WPF
  • 项目中技术使用到WindowsAPIStyleCustomControlJson 序列化和反序列化换肤 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

本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2022-07-01,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 独立观察员博客 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 预览
    • 启动页
      • 嵌入桌面
        • 悬浮桌面
          • 颜色拾取
          • 预览原文
            • 启动页
              • 搜索定位功能 LeftAlt+(应用首字的首字母)
                • 托盘、换肤、透明度
                  • 移动应用顺序
                    • 移除应用
                      • 自动更新(失效)
                        • 参考资料
                        相关产品与服务
                        文件存储
                        文件存储(Cloud File Storage,CFS)为您提供安全可靠、可扩展的共享文件存储服务。文件存储可与腾讯云服务器、容器服务、批量计算等服务搭配使用,为多个计算节点提供容量和性能可弹性扩展的高性能共享存储。腾讯云文件存储的管理界面简单、易使用,可实现对现有应用的无缝集成;按实际用量付费,为您节约成本,简化 IT 运维工作。
                        领券
                        问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档