系统图标-测试
This commit is contained in:
84
Control/Windows/SystemItemWindow.xaml
Normal file
84
Control/Windows/SystemItemWindow.xaml
Normal file
@@ -0,0 +1,84 @@
|
||||
<Window x:Class="GeekDesk.Control.Windows.SystemItemWindow"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:local="clr-namespace:GeekDesk.Control.Windows"
|
||||
xmlns:hc="https://handyorg.github.io/handycontrol"
|
||||
xmlns:uc="clr-namespace:GeekDesk.Control.UserControls.IconFont"
|
||||
mc:Ignorable="d"
|
||||
Title="Svg"
|
||||
Height="520" Width="700"
|
||||
WindowStyle="None"
|
||||
ResizeMode="NoResize"
|
||||
AllowsTransparency="True"
|
||||
Background="Transparent" ShowInTaskbar="False"
|
||||
BorderThickness="0"
|
||||
Focusable="True"
|
||||
KeyDown="OnKeyDown"
|
||||
>
|
||||
<Window.Resources>
|
||||
<Style x:Key="HcTabControl" TargetType="hc:TabControl" BasedOn="{StaticResource TabControlInLine}">
|
||||
<Style.Setters>
|
||||
<Setter Property="Background" Value="Transparent"/>
|
||||
</Style.Setters>
|
||||
</Style>
|
||||
|
||||
<Style x:Key="TabTitle" TargetType="hc:TabItem" BasedOn="{StaticResource TabItemInLine}">
|
||||
<Style.Setters>
|
||||
<Setter Property="Background">
|
||||
<Setter.Value>
|
||||
<SolidColorBrush Color="White" Opacity="0.68"/>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style.Setters>
|
||||
</Style>
|
||||
</Window.Resources>
|
||||
|
||||
<Grid Margin="20">
|
||||
<Grid.Effect>
|
||||
<DropShadowEffect BlurRadius="30" Direction="-90" Color="Gray"
|
||||
RenderingBias="Quality" ShadowDepth="2"/>
|
||||
</Grid.Effect>
|
||||
<Border MouseDown="DragMove" Style="{StaticResource BorderBG}" hc:Dialog.Token="IconUrlDialog">
|
||||
<hc:DialogContainer>
|
||||
<Grid MouseDown="DragMove">
|
||||
<TextBox x:Name="CheckSettingUrl" Visibility="Collapsed" Text="{Binding IsSettingUrl}" TextChanged="CheckSettingUrl_TextChanged"/>
|
||||
<hc:TabControl x:Name="MyTabControl"
|
||||
IsAnimationEnabled="True"
|
||||
SelectionChanged="TabControl_SelectionChanged"
|
||||
ShowContextMenu="True"
|
||||
IsTabFillEnabled="True"
|
||||
Margin="20,30,20,20"
|
||||
Height="350"
|
||||
VerticalAlignment="Top"
|
||||
Style="{StaticResource HcTabControl}">
|
||||
<hc:TabItem Tag="System" IsSelected="True" Header="系统应用" hc:IconElement.Height="16" hc:IconElement.Width="16" hc:IconElement.Geometry="{StaticResource SystemIcon}" Style="{StaticResource TabTitle}">
|
||||
<hc:SimplePanel>
|
||||
<uc:IconPannel x:Name="SystemItem"/>
|
||||
</hc:SimplePanel>
|
||||
</hc:TabItem>
|
||||
<hc:TabItem Tag="System" IsSelected="True" Header="开始菜单应用" hc:IconElement.Height="16" hc:IconElement.Width="16" hc:IconElement.Geometry="{StaticResource SystemIcon}" Style="{StaticResource TabTitle}">
|
||||
<hc:SimplePanel>
|
||||
<uc:IconPannel x:Name="StartMenuItem"/>
|
||||
</hc:SimplePanel>
|
||||
</hc:TabItem>
|
||||
<hc:TabItem Tag="Custom" Header="商店应用" hc:IconElement.Height="16" hc:IconElement.Width="16" hc:IconElement.Geometry="{StaticResource CustomIcon}" Style="{StaticResource TabTitle}">
|
||||
<hc:SimplePanel>
|
||||
<uc:IconPannel x:Name="CustomIcon"/>
|
||||
<hc:LoadingCircle x:Name="LoadingEle"/>
|
||||
</hc:SimplePanel>
|
||||
</hc:TabItem>
|
||||
</hc:TabControl>
|
||||
|
||||
|
||||
<Button Content="取消" Click="Close_Click" Margin="391,397.5,163,22.5"/>
|
||||
<Button Content="自定义设置" Click="CustomButton_Click" IsEnabled="False" Name="CustomButton" Style="{StaticResource Btn1}" Margin="447,397.5,71,22.5"/>
|
||||
<Button Content="确定" Click="Confirm_Click" Style="{StaticResource Btn1}" Margin="534,397.5,20,22.5" />
|
||||
</Grid>
|
||||
</hc:DialogContainer>
|
||||
</Border>
|
||||
</Grid>
|
||||
|
||||
|
||||
</Window>
|
||||
227
Control/Windows/SystemItemWindow.xaml.cs
Normal file
227
Control/Windows/SystemItemWindow.xaml.cs
Normal file
@@ -0,0 +1,227 @@
|
||||
using GeekDesk.Control.Other;
|
||||
using GeekDesk.Interface;
|
||||
using GeekDesk.Util;
|
||||
using GeekDesk.ViewModel;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
|
||||
using System.Windows.Input;
|
||||
using static GeekDesk.Util.ShowWindowFollowMouse;
|
||||
|
||||
namespace GeekDesk.Control.Windows
|
||||
{
|
||||
/// <summary>
|
||||
/// SystemItemWindow.xaml 的交互逻辑
|
||||
/// 添加系统项目到对应菜单
|
||||
/// </summary>
|
||||
public partial class SystemItemWindow : Window, IWindowCommon
|
||||
{
|
||||
private static AppConfig appConfig = MainWindow.appData.AppConfig;
|
||||
private static MenuInfo menuInfo;
|
||||
private static List<IconfontInfo> systemIcons;
|
||||
private static List<IconfontInfo> customIcons;
|
||||
public static IconfontViewModel vm;
|
||||
private SystemItemWindow(List<IconfontInfo> icons, MenuInfo menuInfo)
|
||||
{
|
||||
|
||||
InitializeComponent();
|
||||
|
||||
systemIcons = icons;
|
||||
this.Topmost = true;
|
||||
SystemItemWindow.menuInfo = menuInfo;
|
||||
vm = new IconfontViewModel
|
||||
{
|
||||
Iconfonts = systemIcons
|
||||
};
|
||||
this.DataContext = vm;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 移动窗口
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void DragMove(object sender, System.Windows.Input.MouseButtonEventArgs e)
|
||||
{
|
||||
if (e.LeftButton == MouseButtonState.Pressed)
|
||||
{
|
||||
DragMove();
|
||||
}
|
||||
}
|
||||
|
||||
private void Close_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
this.Close();
|
||||
}
|
||||
|
||||
private void TabControl_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||
{
|
||||
TabItem ti = this.MyTabControl.SelectedItem as TabItem;
|
||||
|
||||
switch (ti.Tag.ToString())
|
||||
{
|
||||
case "Custom":
|
||||
CustomButton.IsEnabled = true;
|
||||
if (StringUtil.IsEmpty(appConfig.CustomIconUrl) || StringUtil.IsEmpty(appConfig.CustomIconJsonUrl))
|
||||
{
|
||||
LoadingEle.Visibility = Visibility.Visible;
|
||||
CustomIcon.Visibility = Visibility.Collapsed;
|
||||
HandyControl.Controls.Dialog.Show(new CustomIconUrlDialog(appConfig), "IconUrlDialog");
|
||||
} else
|
||||
{
|
||||
if (customIcons == null)
|
||||
{
|
||||
vm.Iconfonts = null;
|
||||
LoadingOnlineIcon();
|
||||
} else
|
||||
{
|
||||
vm.Iconfonts = customIcons;
|
||||
LoadingEle.Visibility = Visibility.Collapsed;
|
||||
CustomIcon.Visibility = Visibility.Visible;
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if (CustomButton != null)
|
||||
{
|
||||
CustomButton.IsEnabled = false;
|
||||
}
|
||||
if (vm != null)
|
||||
{
|
||||
vm.Iconfonts = systemIcons;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void Confirm_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
TabItem ti = this.MyTabControl.SelectedItem as TabItem;
|
||||
int index;
|
||||
switch (ti.Tag.ToString())
|
||||
{
|
||||
case "Custom":
|
||||
index = this.CustomIcon.IconListBox.SelectedIndex;
|
||||
if (index != -1)
|
||||
{
|
||||
menuInfo.MenuGeometry = customIcons[index].Text;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
index = this.CustomIcon.IconListBox.SelectedIndex;
|
||||
if (index != -1)
|
||||
{
|
||||
menuInfo.MenuGeometry = systemIcons[index].Text;
|
||||
}
|
||||
break;
|
||||
}
|
||||
this.Close();
|
||||
}
|
||||
|
||||
|
||||
private static System.Windows.Window window = null;
|
||||
public static void Show(List<IconfontInfo> listInfo, MenuInfo menuInfo)
|
||||
{
|
||||
if (window == null || !window.Activate())
|
||||
{
|
||||
window = new SystemItemWindow(listInfo, menuInfo);
|
||||
}
|
||||
window.Show();
|
||||
Keyboard.Focus(window);
|
||||
ShowWindowFollowMouse.Show(window, MousePosition.LEFT_CENTER, 0, 0, false);
|
||||
}
|
||||
|
||||
private void CustomButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
HandyControl.Controls.Dialog.Show(new CustomIconUrlDialog(appConfig));
|
||||
}
|
||||
|
||||
|
||||
private void CheckSettingUrl_TextChanged(object sender, TextChangedEventArgs e)
|
||||
{
|
||||
if (CheckSettingUrl.Text == "true")
|
||||
{
|
||||
LoadingOnlineIcon();
|
||||
} else
|
||||
{
|
||||
LoadingEle.IsRunning = true;
|
||||
CustomIcon.Visibility = Visibility.Collapsed;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void LoadingOnlineIcon()
|
||||
{
|
||||
try
|
||||
{
|
||||
string svgJsStr = HttpUtil.Get(appConfig.CustomIconUrl);
|
||||
string jsonStr = HttpUtil.Get(appConfig.CustomIconJsonUrl);
|
||||
List<IconfontInfo> icons = SvgToGeometry.GetIconfonts(svgJsStr, jsonStr);
|
||||
customIcons = icons;
|
||||
vm.Iconfonts = customIcons;
|
||||
LoadingEle.Visibility = Visibility.Collapsed;
|
||||
CustomIcon.Visibility = Visibility.Visible;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
HandyControl.Controls.Growl.WarningGlobal("加载远程图标异常!");
|
||||
LogUtil.WriteErrorLog(e, "加载远程图标异常!");
|
||||
}
|
||||
}
|
||||
|
||||
public void OnKeyDown(object sender, KeyEventArgs e)
|
||||
{
|
||||
if (e.Key == Key.Escape)
|
||||
{
|
||||
this.Close();
|
||||
}
|
||||
}
|
||||
|
||||
public class IconfontViewModel : INotifyPropertyChanged
|
||||
{
|
||||
private List<IconfontInfo> iconfonts;
|
||||
private string isSettingUrl;
|
||||
|
||||
public List<IconfontInfo> Iconfonts
|
||||
{
|
||||
get
|
||||
{
|
||||
return iconfonts;
|
||||
}
|
||||
set
|
||||
{
|
||||
iconfonts = value;
|
||||
OnPropertyChanged("Iconfonts");
|
||||
}
|
||||
}
|
||||
|
||||
public string IsSettingUrl
|
||||
{
|
||||
get
|
||||
{
|
||||
return isSettingUrl;
|
||||
}
|
||||
set
|
||||
{
|
||||
isSettingUrl = value;
|
||||
OnPropertyChanged("IsSettingUrl");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
private void OnPropertyChanged(string propertyName)
|
||||
{
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -149,6 +149,9 @@
|
||||
<Compile Include="Control\UserControls\IconFont\IconPannel.xaml.cs">
|
||||
<DependentUpon>IconPannel.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Control\Windows\SystemItemWindow.xaml.cs">
|
||||
<DependentUpon>SystemItemWindow.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Control\Windows\ToDoInfoWindow.xaml.cs">
|
||||
<DependentUpon>ToDoInfoWindow.xaml</DependentUpon>
|
||||
</Compile>
|
||||
@@ -215,6 +218,7 @@
|
||||
<Compile Include="Util\ShowWindowFollowMouse.cs" />
|
||||
<Compile Include="Util\StringUtil.cs" />
|
||||
<Compile Include="Util\SvgToGeometry.cs" />
|
||||
<Compile Include="Util\SystemIcon.cs" />
|
||||
<Compile Include="ViewModel\AppConfig.cs" />
|
||||
<Compile Include="ViewModel\AppData.cs" />
|
||||
<Compile Include="ViewModel\ToDoInfo.cs" />
|
||||
@@ -245,6 +249,10 @@
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
<Page Include="Control\Windows\SystemItemWindow.xaml">
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
<SubType>Designer</SubType>
|
||||
</Page>
|
||||
<Page Include="Control\Windows\ToDoInfoWindow.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
|
||||
@@ -72,6 +72,22 @@ namespace GeekDesk.Util
|
||||
ico = Icon.FromHandle(ip);
|
||||
}
|
||||
|
||||
IntPtr hIcon2 = IntPtr.Zero;
|
||||
//TODO
|
||||
for (int i=0; i<=1000; i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
ico = SystemIcon.MyExtractIcon("%SystemRoot%\\system32\\shell32.dll", i, hIcon2);
|
||||
Bitmap bmp2 = ico.ToBitmap();
|
||||
bmp2.Save("d:\\test\\" + i + ".png");
|
||||
} catch
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
ico = SystemIcon.MyExtractIcon("%SystemRoot%\\system32\\shell32.dll", 16, hIcon2);
|
||||
|
||||
Bitmap bmp = ico.ToBitmap();
|
||||
MemoryStream strm = new MemoryStream();
|
||||
|
||||
@@ -80,7 +96,7 @@ namespace GeekDesk.Util
|
||||
EncoderParameter myEncoderParameter = new EncoderParameter(myEncoder, 75L);
|
||||
EncoderParameters myEncoderParameters = new EncoderParameters(1);
|
||||
myEncoderParameters.Param[0] = myEncoderParameter;
|
||||
|
||||
bmp.Save("d:\\test.png");
|
||||
bmp.Save(strm, myImageCodecInfo, myEncoderParameters);
|
||||
BitmapImage bmpImage = new BitmapImage();
|
||||
bmpImage.BeginInit();
|
||||
|
||||
34
Util/SystemIcon.cs
Normal file
34
Util/SystemIcon.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace GeekDesk.Util
|
||||
{
|
||||
public class SystemIcon
|
||||
{
|
||||
[DllImport("Shell32.dll")]
|
||||
public static extern int ExtractIcon(IntPtr h, string strx, int ii);
|
||||
|
||||
public static Icon MyExtractIcon(string FileName, int iIndex, IntPtr h)
|
||||
{
|
||||
try
|
||||
{
|
||||
IntPtr hIcon = (IntPtr)ExtractIcon(h, FileName, iIndex);
|
||||
if (!hIcon.Equals(null))
|
||||
{
|
||||
Icon icon = Icon.FromHandle(hIcon);
|
||||
return icon;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user