From 644a30171672c595d4aca469f0c2cfdfacaf24c8 Mon Sep 17 00:00:00 2001
From: xiu2 <54703944+XIU2@users.noreply.github.com>
Date: Sun, 20 Sep 2020 18:32:33 +0800
Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20=E7=A3=81=E8=B4=B4?=
=?UTF-8?q?=E5=9B=BE=E7=89=87=E9=95=BF=E5=BA=A6/=E5=AE=BD=E5=BA=A6?=
=?UTF-8?q?=E4=BD=8E=E4=BA=8E=20100=20=E5=83=8F=E7=B4=A0=E6=97=B6=E6=8A=A5?=
=?UTF-8?q?=E9=94=99=E7=9A=84=E9=97=AE=E9=A2=98=E3=80=82=20=E4=BF=AE?=
=?UTF-8?q?=E5=A4=8D=20=E7=A3=81=E8=B4=B4=E9=A2=84=E8=A7=88=E6=A1=86?=
=?UTF-8?q?=E7=9A=84=E5=9B=BE=E6=A0=87=E8=BE=B9=E7=BC=98=E6=98=BE=E7=A4=BA?=
=?UTF-8?q?=E9=94=AF=E9=BD=BF=E7=9A=84=E9=97=AE=E9=A2=98=E3=80=82?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
File.cs | 3 +-
Form.Designer.cs | 2 +-
Form.cs | 108 +++++++++++++++++++++++--------------
Other.cs | 7 ++-
Properties/AssemblyInfo.cs | 4 +-
Registry.cs | 10 +++-
6 files changed, 89 insertions(+), 45 deletions(-)
diff --git a/File.cs b/File.cs
index 00c7399..312247a 100644
--- a/File.cs
+++ b/File.cs
@@ -33,7 +33,7 @@ public static string Get_Shortcut_TargetPath_Array(string[] Shortcut_Path, strin
{
foreach (string Temp_Shortcut_Path in Shortcut_Path)
{
- Debug.Print(Temp_Shortcut_Path);
+ //Debug.Print(Temp_Shortcut_Path);
if (Get_Shortcut_TargetPath(Temp_Shortcut_Path) == Path)
{
return Temp_Shortcut_Path;
@@ -42,6 +42,7 @@ public static string Get_Shortcut_TargetPath_Array(string[] Shortcut_Path, strin
}
return null;
}
+
///
/// 创建快捷方式
///
diff --git a/Form.Designer.cs b/Form.Designer.cs
index 539353e..b437350 100644
--- a/Form.Designer.cs
+++ b/Form.Designer.cs
@@ -359,7 +359,7 @@ private void InitializeComponent()
this.PictureBox_磁贴图标预览.Location = new System.Drawing.Point(457, 75);
this.PictureBox_磁贴图标预览.Name = "PictureBox_磁贴图标预览";
this.PictureBox_磁贴图标预览.Size = new System.Drawing.Size(32, 32);
- this.PictureBox_磁贴图标预览.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
+ this.PictureBox_磁贴图标预览.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
this.PictureBox_磁贴图标预览.TabIndex = 24;
this.PictureBox_磁贴图标预览.TabStop = false;
this.toolTip.SetToolTip(this.PictureBox_磁贴图标预览, "磁贴预览框:\r\n按下 [鼠标左键] 开始屏幕取色,松开 [鼠标左键] 停止取色。\r\n单击 [鼠标右键] 重置为系统主题色。\r\n\r\n注意:开启 2004 新版磁贴样" +
diff --git a/Form.cs b/Form.cs
index 79f92db..11c3b78 100644
--- a/Form.cs
+++ b/Form.cs
@@ -140,22 +140,21 @@ public Form(string[] args)
}
else
{
- // 创建一份磁贴(预览框)背景颜色的 Bitmap,用来在遇到有透明图层(png)的图片时,透明的像素点以背景颜色为准,保证磁贴颜色识别准确
+ // 创建一份磁贴(预览框)背景颜色的 Bitmap,在遇到有透明图层(png)的图片时,透明的像素点以背景颜色为准,保证磁贴颜色识别准确
Bitmap BackColor = new Bitmap(100, 100);
Graphics Temp_BackColor = Graphics.FromImage(BackColor);
Temp_BackColor.Clear(PictureBox_磁贴图片预览.BackColor);
Temp_BackColor.Dispose();
Color Back_PixelColor = BackColor.GetPixel(50, 50);
- Bitmap ImageColor = (Bitmap)PictureBox_磁贴图片预览.Image;
- ImageColor.SetResolution(100, 100);
+ Bitmap ImageColor = new Bitmap((Bitmap)PictureBox_磁贴图片预览.Image, new Size(100, 100)); // 和图片框一样强制拉伸到 100*100 像素
double Red = 0, Green = 0, Blue = 0;
//double Alpha = 0;
- for (int temp_y = 0; temp_y < 16; temp_y++)
+ for (int temp_y = 0; temp_y < 30; temp_y++)
{
for (int temp_x = 0; temp_x < 92; temp_x++)
{
- Color Image_PixelColor = ImageColor.GetPixel(5 + temp_x, 79 + temp_y);
+ Color Image_PixelColor = ImageColor.GetPixel(5 + temp_x, 65 + temp_y);
if (Image_PixelColor.A == 0)
{
//Alpha += Back_PixelColor.A;
@@ -175,11 +174,11 @@ public Form(string[] args)
}
//BackColor.Dispose();
//ImageColor.Dispose();
- //Alpha /= 1472;
- Red /= 1472;
- Green /= 1472;
- Blue /= 1472;
- //Debug.Print(Alpha.ToString() + " " + Red.ToString() + " " + Green.ToString() + " " + Blue.ToString() + " " + (Red * 0.299 + Green * 0.578 + Blue * 0.114).ToString());
+ //Alpha /= 2760;
+ Red /= 2760;
+ Green /= 2760;
+ Blue /= 2760;
+ //Debug.Print(Red.ToString() + " " + Green.ToString() + " " + Blue.ToString() + " " + (Red * 0.299 + Green * 0.578 + Blue * 0.114).ToString());
if (Red * 0.299 + Green * 0.578 + Blue * 0.114 >= 168)
{
Label_磁贴名称预览.ForeColor = Color.Black;
@@ -400,7 +399,7 @@ public Form(string[] args)
{
Temp_Square150x150Logo = Path.GetFileNameWithoutExtension(TextBox_程序路径.Text) + ".150x150Logo" + Path.GetExtension(TextBox_磁贴图片.Text);
}
- Debug.Print(Temp_BackgroundColor + "|" + Temp_ShowNameOnSquare150x150Logo + "|" + Temp_ForegroundText + "|" + Temp_Square150x150Logo + "|" + TextBox_磁贴图标.Text);
+ //Debug.Print(Temp_BackgroundColor + "|" + Temp_ShowNameOnSquare150x150Logo + "|" + Temp_ForegroundText + "|" + Temp_Square150x150Logo + "|" + TextBox_磁贴图标.Text);
// 开始写入配置
XElement XML_Application = new XElement("Application",
new XAttribute(XNamespace.Xmlns + "xsi", "http://www.w3.org/2001/XMLSchema-instance"));
@@ -679,24 +678,7 @@ private void Button_显示文字_TextChanged(object sender, EventArgs e)
}
}
- private void Label_程序路径_MouseClick(object sender, MouseEventArgs e) // 点击标签后,置焦点为输入框,下同
- {
- TextBox_程序路径.Focus();
- }
- private void Label_磁贴名称_MouseClick(object sender, MouseEventArgs e)
- {
- TextBox_磁贴名称.Focus();
- }
- private void Label_磁贴图片_MouseClick(object sender, MouseEventArgs e)
- {
- TextBox_磁贴图片.Focus();
- }
- private void Label_磁贴图标_MouseClick(object sender, MouseEventArgs e)
- {
- TextBox_磁贴图标.Focus();
- }
-
- private void TextBox_程序路径_TextChanged(object sender, EventArgs e) // 输入框内容更改后,置焦点为输入框
+ private void TextBox_程序路径_TextChanged(object sender, EventArgs e) // 内容更改后,读入程序路径
{
TextBox_程序路径_Leave_2();
if (TextBox_程序路径.Text != "")
@@ -759,7 +741,7 @@ private void TextBox_磁贴名称_TextChanged(object sender, EventArgs e)
Button_添加磁贴.Enabled = true; // 磁贴名称不等于空时,允许添加磁贴按钮
}
}
- private void TextBox_磁贴图片_TextChanged(object sender, EventArgs e)
+ private void TextBox_磁贴图片_TextChanged(object sender, EventArgs e) // 内容更改后,读入图片
{
if (TextBox_磁贴图片.Text != "")
{
@@ -767,9 +749,15 @@ private void TextBox_磁贴图片_TextChanged(object sender, EventArgs e)
{
if (PictureBox_磁贴图片预览.Image != null)
{
- PictureBox_磁贴图片预览.Image.Dispose();
+ PictureBox_磁贴图片预览.Image.Dispose(); // 释放旧资源
}
- PictureBox_磁贴图片预览.Image = Image.FromFile(TextBox_磁贴图片.Text);
+ FileStream Temp_ImageStream = new FileStream(TextBox_磁贴图片.Text, FileMode.Open, FileAccess.Read); // 打开文件流
+ int Temp_ImageByteLength = (int)Temp_ImageStream.Length;
+ byte[] Temp_ImageFileBytes = new byte[Temp_ImageByteLength];
+ Temp_ImageStream.Read(Temp_ImageFileBytes, 0, Temp_ImageByteLength);
+ Temp_ImageStream.Close(); // 文件流关闭,文件解除锁定
+ PictureBox_磁贴图片预览.Image = Image.FromStream(new MemoryStream(Temp_ImageFileBytes)); // 从流中读入图片
+ //PictureBox_磁贴图片预览.Image = Image.FromFile(TextBox_磁贴图片.Text); // 旧载入方式,会锁定文件
Recognize_Text_Color(); // 识别图片颜色
TextBox_磁贴图标.Text = "";
PictureBox_磁贴图标预览.Image = null;
@@ -790,19 +778,32 @@ private void TextBox_磁贴图片_TextChanged(object sender, EventArgs e)
TextBox_磁贴图片_Leave_2();
}
}
- private void TextBox_磁贴图标_TextChanged(object sender, EventArgs e)
+ private void TextBox_磁贴图标_TextChanged(object sender, EventArgs e) // 内容更改后,读入图标
{
if(TextBox_磁贴图标.Text != "")
{
if (System.IO.File.Exists(TextBox_磁贴图标.Text))
{
+ if (PictureBox_磁贴图标预览.Image != null)
+ {
+ PictureBox_磁贴图标预览.Image.Dispose(); // 释放旧资源
+ }
if (Path.GetExtension(TextBox_磁贴图标.Text).ToLower() == ".exe")
{
- PictureBox_磁贴图标预览.Image = Bitmap.FromHicon(System.Drawing.Icon.ExtractAssociatedIcon(TextBox_磁贴图标.Text).Handle);
+ PictureBox_磁贴图标预览.Image = System.Drawing.Icon.ExtractAssociatedIcon(TextBox_磁贴图标.Text).ToBitmap();
+ //PictureBox_磁贴图标预览.Image = Bitmap.FromHicon(System.Drawing.Icon.ExtractAssociatedIcon(TextBox_磁贴图标.Text).Handle); // 旧载入方式,有锯齿
}
else if(Path.GetExtension(TextBox_磁贴图标.Text).ToLower() == ".ico")
{
- PictureBox_磁贴图标预览.Image = Bitmap.FromHicon(new Icon(TextBox_磁贴图标.Text, new Size(32, 32)).Handle);
+ FileStream Temp_IconStream = new FileStream(TextBox_磁贴图标.Text, FileMode.Open, FileAccess.Read); // 打开文件流
+ int Temp_IconByteLength = (int)Temp_IconStream.Length;
+ byte[] Temp_IconFileBytes = new byte[Temp_IconByteLength];
+ Temp_IconStream.Read(Temp_IconFileBytes, 0, Temp_IconByteLength);
+ Temp_IconStream.Close(); // 文件流关闭,文件解除锁定
+ PictureBox_磁贴图标预览.Image = Image.FromStream(new MemoryStream(Temp_IconFileBytes)); // 从流中读入图标
+
+ //PictureBox_磁贴图标预览.ImageLocation = TextBox_磁贴图标.Text; // 旧载入方式,无锯齿,但会锁定文件
+ //PictureBox_磁贴图标预览.Image = Bitmap.FromHicon(new Icon(TextBox_磁贴图标.Text, 32, 32).Handle); // 旧载入方式,有锯齿
}
TextBox_磁贴图片.Text = "";
PictureBox_磁贴图片预览.Image = null;
@@ -831,7 +832,7 @@ private void TextBox_磁贴图标_TextChanged(object sender, EventArgs e)
{
TextBox_磁贴图片.Text = null;
PictureBox_磁贴图片预览.Image = null;
- if (TextBox_磁贴图标.Text == "") // 如果图标也是空的话,那就指定为程序文件
+ if (TextBox_磁贴图标.Text == "") // 如果图标路径也是空的话,那就指定为程序文件
{
TextBox_磁贴图标.Text = TextBox_程序路径.Text;
}
@@ -841,8 +842,15 @@ private void TextBox_磁贴图标_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == 8)
{
- TextBox_磁贴图标.Text = null;
- PictureBox_磁贴图标预览.Image = null;
+ if (TextBox_磁贴图标.Text != TextBox_程序路径.Text) // 如果图标路径等于程序路径,那就没必要继续无意义动作了
+ {
+ TextBox_磁贴图标.Text = null;
+ PictureBox_磁贴图标预览.Image = null;
+ if (TextBox_磁贴图片.Text == "") // 如果图片路径也是空的话,那就指定图标为程序路径
+ {
+ TextBox_磁贴图标.Text = TextBox_程序路径.Text;
+ }
+ }
}
}
private void TextBox_程序路径_KeyPress(object sender, KeyPressEventArgs e)
@@ -852,6 +860,7 @@ private void TextBox_程序路径_KeyPress(object sender, KeyPressEventArgs e)
Init_Config();
}
}
+
private void TextBox_程序路径_Enter(object sender, EventArgs e) // 输入框获得焦点后,置顶并修改背景颜色,下同
{
TextBox_程序路径.BringToFront();
@@ -940,6 +949,10 @@ private void TextBox_磁贴图标_Leave_2()
if (TextBox_磁贴图标.Text == "")
{
TextBox_磁贴图标.SendToBack();
+ if (PictureBox_磁贴图标预览.Image != null)
+ {
+ PictureBox_磁贴图标预览.Image.Dispose();
+ }
}
else
{
@@ -948,7 +961,24 @@ private void TextBox_磁贴图标_Leave_2()
TextBox_磁贴图标.BackColor = Color.WhiteSmoke;
Label_磁贴图标.BackColor = Color.WhiteSmoke;
}
-
+
+ private void Label_程序路径_MouseClick(object sender, MouseEventArgs e) // 点击标签后,置焦点为输入框,下同
+ {
+ TextBox_程序路径.Focus();
+ }
+ private void Label_磁贴名称_MouseClick(object sender, MouseEventArgs e)
+ {
+ TextBox_磁贴名称.Focus();
+ }
+ private void Label_磁贴图片_MouseClick(object sender, MouseEventArgs e)
+ {
+ TextBox_磁贴图片.Focus();
+ }
+ private void Label_磁贴图标_MouseClick(object sender, MouseEventArgs e)
+ {
+ TextBox_磁贴图标.Focus();
+ }
+
private void PictureBox_磁贴图片预览_MouseDown(object sender, MouseEventArgs e) // 图片预览框 鼠标按下开始取色
{
if (e.Button == MouseButtons.Left)
diff --git a/Other.cs b/Other.cs
index 2aac02d..64a4463 100644
--- a/Other.cs
+++ b/Other.cs
@@ -23,6 +23,12 @@ public class Color
private static extern int ReleaseDC(int hwnd, int hdc); // 释放DC
[System.Runtime.InteropServices.DllImport("gdi32")]
private static extern int GetPixel(int hdc, int x, int y);
+ ///
+ /// 获取屏幕指定像素点HEX颜色值
+ ///
+ /// X
+ /// Y
+ /// HEX颜色值,不带 #
public static string Get_ScreenColor(int x, int y)
{
//Debug.Print(x + "," + y); // 把坐标显示到窗口上
@@ -34,7 +40,6 @@ public static string Get_ScreenColor(int x, int y)
//Debug.Print(c.ToString()); // 输出10进制颜色
//Debug.Print(r.ToString("x").PadLeft(2, '0') + g.ToString("x").PadLeft(2, '0') + b.ToString("x").PadLeft(2, '0')); // 输出16进制颜色
//Debug.Print(r.ToString() + ',' + g.ToString() + ',' + b.ToString()); // 输出RGB
- //PictureBox_磁贴图片预览.BackColor = Color.FromArgb(r, g, b); //设置颜色框
ReleaseDC(0, Temp_hDc);
return (r.ToString("x").PadLeft(2, '0') + g.ToString("x").PadLeft(2, '0') + b.ToString("x").PadLeft(2, '0'));
}
diff --git a/Properties/AssemblyInfo.cs b/Properties/AssemblyInfo.cs
index 62b5676..842f57a 100644
--- a/Properties/AssemblyInfo.cs
+++ b/Properties/AssemblyInfo.cs
@@ -32,5 +32,5 @@
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值
//通过使用 "*",如下所示:
// [assembly: AssemblyVersion("1.0.*")]
-[assembly: AssemblyVersion("4.0.8.0")]
-[assembly: AssemblyFileVersion("4.0.8.0")]
+[assembly: AssemblyVersion("4.0.9.0")]
+[assembly: AssemblyFileVersion("4.0.9.0")]
diff --git a/Registry.cs b/Registry.cs
index cfc7d0b..365cc2e 100644
--- a/Registry.cs
+++ b/Registry.cs
@@ -31,6 +31,7 @@ public static bool Check(string Name, string Extension = "")
return true;
}
}
+
///
/// 添加右键菜单
///
@@ -105,6 +106,7 @@ public static bool Add(string Name, string Path, bool NoIcon = true, string Icon
}
}
}
+
///
/// 删除右键菜单
///
@@ -161,6 +163,7 @@ public static string Get_SystemColor()
}
return ((int)Registry.GetValue(@"HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\DWM", "ColorizationColor", 1052688)).ToString("x8").Substring(2);
}
+
///
/// 获取系统主题模式(浅色/深色)
///
@@ -178,6 +181,7 @@ public static bool Get_SystemUsesLightTheme()
}
return false;
}
+
///
/// 获取开始菜单(磁贴)、任务栏、操作中心等是否使用主题色
///
@@ -195,6 +199,7 @@ public static bool Get_SystemColorPrevalence()
}
return true;
}
+
///
/// 获取系统是否开启透明效果
///
@@ -219,6 +224,7 @@ public static string Get_DisplayVersion()
{
return (string)Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "DisplayVersion", null);
}
+
///
/// 获取系统发行ID(例:2004)
///
@@ -227,6 +233,7 @@ public static string Get_ReleaseId()
{
return (string)Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "ReleaseId", null);
}
+
///
/// 获取系统当前版本号(例:19041)
///
@@ -235,6 +242,7 @@ public static string Get_CurrentBuild()
{
return (string)Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "CurrentBuild", null);
}
+
///
/// 获取系统当前内部版本号(例:19041)
///
@@ -256,7 +264,7 @@ public static bool Get_NewTileState()
{
return false;
}
- Debug.Print(Registry.GetValue(@"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FeatureManagement\Overrides\0\2093230218", "EnabledState", null).ToString());
+ //Debug.Print(Registry.GetValue(@"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FeatureManagement\Overrides\0\2093230218", "EnabledState", null).ToString());
if (Registry.GetValue(@"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FeatureManagement\Overrides\0\2093230218", "EnabledState", null) == null)
{
return false;