Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit1c85a01

Browse files
committed
now can use custom icon (place icon.ico into same folder as exe)fixes#127
1 parentf7f3903 commit1c85a01

File tree

2 files changed

+42
-4
lines changed

2 files changed

+42
-4
lines changed

‎UnityLauncherPro/MainWindow.xaml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
</ControlTemplate>
3131
</Button.Template>
3232
</Button>
33-
<ImageSource="Images/icon.png" RenderOptions.BitmapScalingMode="NearestNeighbor"HorizontalAlignment="Left"Width="16"Height="16"Margin="4,0,0,0"SnapsToDevicePixels="True"UseLayoutRounding="True" />
33+
<ImageSource="Images/icon.png"x:Name="IconImage"RenderOptions.BitmapScalingMode="NearestNeighbor"HorizontalAlignment="Left"Width="16"Height="16"Margin="4,0,0,0"SnapsToDevicePixels="True"UseLayoutRounding="True" />
3434
<LabelContent="UnityLauncherPro"IsHitTestVisible="False"Margin="19,0,0,-5"Foreground="{DynamicResource ThemeMainTitle}"FontSize="12"HorizontalAlignment="Left" />
3535
<!-- minimize-->
3636
<Buttonx:Name="btnMinimize"BorderThickness="0"Style="{StaticResource {x:Static ToolBar.ButtonStyleKey}}"HorizontalAlignment="Right"VerticalAlignment="Top"Height="23"Width="23"Background="Transparent"Click="BtnMinimize_Click"Margin="0,0,27,0"Padding="2,0,2,8"IsTabStop="False">

‎UnityLauncherPro/MainWindow.xaml.cs‎

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818
usingSystem.Windows.Controls;
1919
usingSystem.Windows.Data;
2020
usingSystem.Windows.Input;
21+
usingSystem.Windows.Interop;
2122
usingSystem.Windows.Media;
23+
usingSystem.Windows.Media.Imaging;
2224
usingSystem.Windows.Shell;
2325
usingUnityLauncherPro.Data;
2426
usingUnityLauncherPro.Helpers;
@@ -45,7 +47,7 @@ public partial class MainWindow : Window
4547
conststringgithubURL="https://github.com/unitycoder/UnityLauncherPro";
4648
conststringresourcesURL="https://github.com/unitycoder/UnityResources";
4749
conststringdefaultAdbLogCatArgs="-s Unity ActivityManager PackageManager dalvikvm DEBUG -v color";
48-
System.Windows.Forms.NotifyIconnotifyIcon;
50+
System.Windows.Forms.NotifyIconnotifyIcon=newSystem.Windows.Forms.NotifyIcon();
4951

5052
UnityVersion[]updatesSource;
5153
publicstaticList<string>updatesAsStrings=newList<string>();
@@ -110,6 +112,8 @@ void Init()
110112
{
111113
lblVersion.Content="Build: "+Version.Stamp;
112114
}
115+
116+
CheckCustomIcon();
113117
}
114118

115119
voidStart()
@@ -160,8 +164,6 @@ void Start()
160164
gridBuildReportData.Items.Clear();
161165

162166
// build notifyicon (using windows.forms)
163-
notifyIcon=newSystem.Windows.Forms.NotifyIcon();
164-
notifyIcon.Icon=newIcon(Application.GetResourceStream(newUri("pack://application:,,,/Images/icon.ico")).Stream);
165167
notifyIcon.MouseClick+=newSystem.Windows.Forms.MouseEventHandler(NotifyIcon_MouseClick);
166168

167169
// get original colors
@@ -3756,7 +3758,43 @@ private void OnPipeConnection(IAsyncResult result)
37563758
}
37573759
}
37583760

3761+
privatevoidCheckCustomIcon()
3762+
{
3763+
stringcustomIconPath=Path.Combine(Environment.CurrentDirectory,"icon.ico");
3764+
Console.WriteLine(customIconPath);
37593765

3766+
if(File.Exists(customIconPath))
3767+
{
3768+
try
3769+
{
3770+
// Load the custom icon using System.Drawing.Icon
3771+
using(varicon=newSystem.Drawing.Icon(customIconPath))
3772+
{
3773+
// Convert the icon to a BitmapSource and assign it to the WPF window's Icon property
3774+
this.Icon=Imaging.CreateBitmapSourceFromHIcon(
3775+
icon.Handle,
3776+
Int32Rect.Empty,
3777+
BitmapSizeOptions.FromEmptyOptions()// Use BitmapSizeOptions here
3778+
);
3779+
3780+
// window icon
3781+
IconImage.Source=this.Icon;
3782+
// tray icon
3783+
notifyIcon.Icon=newIcon(customIconPath);
3784+
}
3785+
}
3786+
catch(Exceptionex)
3787+
{
3788+
SetStatus("Failed to load custom icon: "+ex.Message,MessageType.Warning);
3789+
Debug.WriteLine($"Failed to load custom icon:{ex.Message}");
3790+
}
3791+
}
3792+
else// no custom icon found
3793+
{
3794+
notifyIcon.Icon=newIcon(Application.GetResourceStream(newUri("pack://application:,,,/Images/icon.ico")).Stream);
3795+
//Debug.WriteLine("Custom icon not found. Using default.");
3796+
}
3797+
}
37603798
//private void menuProjectProperties_Click(object sender, RoutedEventArgs e)
37613799
//{
37623800
// var proj = GetSelectedProject();

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp