普通视图

发现新文章,点击刷新页面。
昨天以前AlexSJC 的博客

7-Zip 美化

作者 AlexSJC
2024年2月24日 21:34

【官网】https://7-zip.org/

7-Zip Theme Manager

推荐
https://www.deviantart.com/masamunecyrus/art/7-Zip-Toolbar-Theme-Office-2013-550865514
https://www.deviantart.com/alexgal23/art/Pure-Flat-2016-7-Zip-theme-598604939
https://www.deviantart.com/alexgal23/art/New-Design-7-Zip-theme-899211552
https://www.deviantart.com/alexgal23/art/Diamin-7-Zip-theme-776800854
https://www.deviantart.com/alexgal23/art/Shirae-7-Zip-theme-505904456
https://www.deviantart.com/ivan13x/art/Windows-11-Theme-885090687

C# 单例应用

作者 AlexSJC
2024年2月3日 20:34
using System.Reflection;
using System.Threading;

public enum MutexScope
{
    Local,
    Global
}

public static class SingletonApp
{
    private static Mutex? mutex;

    public static bool IsNew { get; private set; }

    public static bool Check()
    {
        return Check(MutexScope.Local);
    }

    public static bool Check(MutexScope scope)
    {
        return Check($"{scope}\\{Assembly.GetEntryAssembly()?.GetName().Name}");
    }

    public static bool Check(string name)
    {
        bool createdNew;
        mutex = new(true, name, out createdNew);
        IsNew = createdNew;
        return createdNew;
    }

    public static void Cleanup()
    {
        mutex?.Close();
    }
}

C# 各类方式获取应用程序路径

作者 AlexSJC
2024年1月24日 14:14

步骤

ConsoleApp1 调用 ClassLibrary1 的方法。

在 CMD 运行,输出的内容如下图所示。

归纳即可得到下表。

Process.GetCurrentProcess().MainModule.FileName…\ConsoleApp1.exe
Assembly.GetCallingAssembly().Location…\ConsoleApp1.dll
Assembly.GetEntryAssembly().Location…\ConsoleApp1.dll
Assembly.GetExecutingAssembly().Location…\ClassLibrary1.dll
AppDomain.CurrentDomain.BaseDirectory…\net8.0\
AppDomain.CurrentDomain.SetupInformation.ApplicationBase…\net8.0\
AppContext.BaseDirectory…\net8.0\
Directory.GetCurrentDirectory()…\Administrator
Environment.CurrentDirectory…\Administrator
C:\Users\Administrator 为工作目录(从中启动)

说明

Assembly.Get*Assembly()

Assembly.GetCallingAssembly 返回方法(该方法调用当前正在执行的方法)的 Assembly

Assembly.GetEntryAssembly 获取默认应用程序域中的进程可执行文件。 在其他的应用程序域中,这是由 ExecuteAssembly(String) 执行的第一个可执行文件。

Assembly.GetExecutingAssembly 获取包含当前执行的代码的程序集。

举例

如一个程序MyApp.exe,在程序中引用了MyDll.dll类库,而在MyDll.dll中有一个MyInfo方法,MyInfo调用了MyDll2.dll中的MyInfo2方法,那么结果如下: 

在MyApp.exe调用任何一个方法,获得的都是MyApp.exe的程序集信息。 

通过MyApp调用MyDll.MyInfo方法时,在MyDll.MyInfo中: 

  • 执行GetEntryAssembly,获得的是MyApp.exe的程序集信息。 
  • 执行GetExecutingAssembly,获得的是MyDll.dll的程序集信息。 
  • 执行GetCallingAssembly,获得的是MyApp.exe的程序集信息。 

通过MyDll的方法调用MyDll2.MyInfo2方法时: 

  • 执行GetEntryAssembly,获得的是MyApp.exe的程序集信息。 
  • 执行GetExecutingAssembly,获得的是MyDll2.dll的程序集信息。 
  • 执行GetCallingAssembly,获得的是MyDll.dll的程序集信息。
Assembly.Get***Assembly的区别_assembly.getassembly()-CSDN博客

元素周期表

作者 AlexSJC
2023年12月18日 21:16
基于 ACS 的 Periodic Table of Chemical Elements 修改制作而成。

元素周期表(Periodic table of elements),根据原子序数的递增,将所有已发现的化学元素组织在行(周期)和列(族)中。科学家使用元素周期表快速查询元素的信息,例如原子质量和符号。元素周期表的排列还使科学家能够辨别元素特性的趋势,包括电负性、电离能和原子半径。

许多科学家致力于化学元素的组织问题,但德米特里·伊万诺维奇·门捷列夫于 1869 年发布了他的第一个版本的周期表,并通常被认为是元素周期表的发明者。此后,元素周期表不断发展,反映了 150 多年的科学发展以及对化学和物理学的理解。如今,它已拥有 118 种已知元素,被广泛认为是科学领域最重要的成就之一。

WPF 工具窗口

作者 AlexSJC
2023年12月12日 20:06

更改指定窗口的属性。 函数还将指定偏移量的 32 位 (长) 值设置为额外的窗口内存。

SetWindowLongA 函数 (winuser.h)

WS_EX_TOOLWINDOW

该窗口旨在用作浮动工具栏。 工具窗口具有短于普通标题栏的标题栏和使用较小的字体绘制的窗口标题。 工具窗口不会显示在任务栏中,也不会显示在用户按 Alt+TAB 时显示的对话框中。 如果工具窗口具有系统菜单,则其图标不会显示在标题栏上。 但是,可以通过右键单击或键入 ALT+SPACE 来显示系统菜单。

扩展的窗口样式
[DllImport("user32.dll")]
private static extern long SetWindowLong(IntPtr hWnd, int nIndex, long dwNewLong);

protected override void OnSourceInitialized(EventArgs e)
{
    base.OnSourceInitialized(e);
    SetWindowLong(new WindowInteropHelper(this).Handle, -20, 0x00000080L);
}

C# 通配符

作者 AlexSJC
2023年12月3日 16:15
using System.Text.RegularExpressions;

public class Wildcard
{
    public static string ToRegex(string pattern)
    {
        return $"^{Regex.Escape(pattern).Replace("\\*", ".*").Replace("\\?", ".")}$";
    }

    public static bool IsMatch(string input, string pattern)
    {
        return Regex.IsMatch(input, ToRegex(pattern));
    }
}

Xamarin.Android 请求忽略电池优化

作者 AlexSJC
2023年11月12日 13:22
<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" />
if (Build.VERSION.SdkInt >= BuildVersionCodes.M)
{
    PowerManager pm = (PowerManager)GetSystemService(PowerService);
    if (!pm.IsIgnoringBatteryOptimizations(PackageName))
    {
        Intent intent = new(Settings.ActionRequestIgnoreBatteryOptimizations);
        intent.SetData(Android.Net.Uri.Parse($"package:{PackageName}"));
        StartActivity(intent);
    }
}

https://developer.android.google.cn/training/monitoring-device-state/doze-standby?hl=zh-cn#support_for_other_use_cases

NAPS2

作者 AlexSJC
2023年9月16日 10:36

NAPS2 – Not Another PDF Scanner
Scan documents to PDF and more, as simply as possible.

NAPS2 是适用于 Windows、Mac 和 Linux 的免费开源扫描软件。

使用 Canon、Brother、HP、Epson、Fujitsu 等设备轻松扫描。然后只需单击一下即可保存为 PDF、TIFF、JPEG 或 PNG。

下载:naps2.com/download

❌
❌