新增DELL 螢幕控制開關

This commit is contained in:
DangHome
2023-07-02 22:17:57 +08:00
parent f0b02be1a5
commit a48d7b8d56
16 changed files with 850 additions and 137 deletions

View File

@@ -11,6 +11,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Language", "Language\Langua
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tester", "Tester\Tester.csproj", "{0D34DD73-3282-40EB-8F59-DF190944BF12}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DellMonitorControl", "DellMonitorControl\DellMonitorControl.csproj", "{64E96610-D431-40B9-A00B-55CE195B4B58}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -33,6 +35,10 @@ Global
{0D34DD73-3282-40EB-8F59-DF190944BF12}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0D34DD73-3282-40EB-8F59-DF190944BF12}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0D34DD73-3282-40EB-8F59-DF190944BF12}.Release|Any CPU.Build.0 = Release|Any CPU
{64E96610-D431-40B9-A00B-55CE195B4B58}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{64E96610-D431-40B9-A00B-55CE195B4B58}.Debug|Any CPU.Build.0 = Debug|Any CPU
{64E96610-D431-40B9-A00B-55CE195B4B58}.Release|Any CPU.ActiveCfg = Release|Any CPU
{64E96610-D431-40B9-A00B-55CE195B4B58}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View File

@@ -0,0 +1,17 @@
<Application x:Class="DellMonitorControl.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:DellMonitorControl"
StartupUri="MainWindow.xaml">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/Style/Color.xaml"/>
<ResourceDictionary Source="/Images/Icons.xaml"/>
<ResourceDictionary Source="/Style/Main.xaml"/>
<ResourceDictionary Source="/Style/Btn.xaml"/>
<ResourceDictionary Source="/Style/Slider.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>

View File

@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
namespace DellMonitorControl
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
}
}

View File

@@ -0,0 +1,10 @@
using System.Windows;
[assembly: ThemeInfo(
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
//(used if a resource is not found in the page,
// or application resource dictionaries)
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
//(used if a resource is not found in the page,
// app, or any theme specific resource dictionaries)
)]

View File

@@ -0,0 +1,27 @@
<UserControl x:Class="DellMonitorControl.ControlPanel"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:DellMonitorControl"
mc:Ignorable="d">
<Grid>
<Border Background="{DynamicResource H3}" CornerRadius="10" MouseLeave="Border_MouseLeave"/>
<StackPanel>
<StackPanel Orientation="Vertical" Margin="10,5,5,0">
<TextBlock Text="DELL U3223QE (Center)" Style="{StaticResource TitleStyle}" HorizontalAlignment="Left"/>
<Button Tag="BR974P3" Content="Sleep" Click="ToggleButton_Checked" Style="{StaticResource TextButtonStyle}"/>
</StackPanel>
<StackPanel Orientation="Vertical" Margin="10,5,5,0">
<TextBlock Text="DELL U3223QE (Right)" Style="{StaticResource TitleStyle}" HorizontalAlignment="Left"/>
<Button Tag="CBBP3P3" Content="Sleep" Click="ToggleButton_Checked" Style="{StaticResource TextButtonStyle}"/>
</StackPanel>
<StackPanel Orientation="Vertical" Margin="10,5,5,0">
<TextBlock Text="DELL UP2716D (Left)" Style="{StaticResource TitleStyle}" HorizontalAlignment="Left"/>
<Button Tag="KV97067ICLCL" Content="Sleep" Click="ToggleButton_Checked" Style="{StaticResource TextButtonStyle}"/>
</StackPanel>
</StackPanel>
</Grid>
</UserControl>

View File

@@ -0,0 +1,40 @@
using CMM.Library.Method;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Input;
namespace DellMonitorControl;
/// <summary>
/// Interaction logic for ControlPanel.xaml
/// </summary>
public partial class ControlPanel : UserControl
{
public ControlPanel()
{
InitializeComponent();
}
private void Border_MouseLeave(object sender, MouseEventArgs e)
{
}
private async void ToggleButton_Checked(object sender, RoutedEventArgs e)
{
var toggle = sender as Button;
var tag = toggle?.Tag.ToString();
var content = toggle?.Content as string;
if (content == "Sleep")
{
await CMMCommand.Sleep(tag);
toggle!.Content = "PowerOn";
}
else
{
await CMMCommand.PowerOn(tag);
toggle!.Content = "Sleep";
}
}
}

View File

Binary file not shown.

After

Width:  |  Height:  |  Size: 430 KiB

View File

@@ -0,0 +1,29 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net6.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<AssemblyName>DellMonitorControl</AssemblyName>
<RootNamespace>DellMonitorControl</RootNamespace>
<Product>DellMonitorControl</Product>
<UseWPF>true</UseWPF>
</PropertyGroup>
<ItemGroup>
<None Remove="DellLogo.ico" />
</ItemGroup>
<ItemGroup>
<Resource Include="DellLogo.ico" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Hardcodet.Wpf.TaskbarNotification.Net6" Version="1.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Library\Library.csproj" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,24 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Style x:Key="PathFill" TargetType="Path">
<Setter Property="Stretch" Value="Uniform"/>
<Setter Property="Fill" Value="{DynamicResource F3}"/>
</Style>
<!--Path Minimized-->
<Style x:Key="PathMinimized" TargetType="Path" BasedOn="{StaticResource PathFill}">
<Setter Property="Data" Value="F1 M512,512z M0,0z M107.38,241.56C108.86,241.12 110.41,241.03 111.95,241 207.98,241 304.01,241 400.05,241 407.85,240.59 415.24,247.15 415.52,255.01 416.16,261.91 411.26,268.64 404.62,270.43 401.48,271.29 398.2,270.94 395,271.01 300.65,270.99 206.3,271.01 111.95,271 104.15,271.4 96.76,264.84 96.48,256.99 95.83,250.08 100.74,243.35 107.38,241.56z"/>
</Style>
<!--Path Frame-->
<Style x:Key="PathFrame" TargetType="Path" BasedOn="{StaticResource PathFill}">
<Setter Property="Data" Value="F1 M512,512z M0,0z M94.22,0L417.79,0C441.21,0.19 464.38,9.46 481.47,25.48 500.23,42.75 511.5,67.76 512,93.26L512,420.97C510.85,442.12 502.78,462.87 488.82,478.86 471.32,499.41 444.76,511.82 417.76,512L94.27,512C73.21,511.75 52.27,504.36 35.88,491.09 14,473.85 0.5,446.62 0,418.76L0,93.25C0.49,68.71 10.9,44.57 28.49,27.46 45.77,10.27 69.85,0.21 94.22,0 M85.61,30.72C68.33,33.24 52.3,43.14 42.24,57.39 34.1,68.48 29.86,82.28 30,96 30,202.67 30,309.34 30,416.01 29.89,427.61 32.9,439.23 38.74,449.26 48.08,465.41 64.52,477.36 82.9,480.79 90.5,482.38 98.29,481.94 105.99,482 209.31,482 312.63,482 415.95,482 422.69,482.03 429.44,481.08 435.89,479.11 457.54,472.56 475.05,454 480.17,431.95 482.47,423.13 481.96,413.95 482,404.92 481.99,301.59 482.02,198.26 481.99,94.93 481.99,76.98 474.07,59.28 460.78,47.24 449.05,36.27 433.08,30.04 417.03,30.01 310.01,29.99 202.99,30.01 95.97,30 92.5,30 89.03,30.22 85.61,30.72z"/>
</Style>
<!--Path Cancel-->
<Style x:Key="PathCancel" TargetType="Path" BasedOn="{StaticResource PathFill}">
<Setter Property="Data" Value="F1 M512,512z M0,0z M54.26,54.35C61.42,47.02 73.03,44.46 82.6,48.18 87.07,49.61 90.87,52.58 94.06,55.96 148.04,109.95 202.04,163.92 256,217.93 310.65,163.25 365.32,108.6 419.98,53.94 427.23,47.02 438.47,44.53 447.88,48.13 461.06,52.46 469.23,68.21 464.66,81.42 463.27,86.72 459.86,91.21 455.92,94.91 414.26,136.58 372.59,178.24 330.93,219.92 318.68,231.96 306.81,244.43 294.33,256.22 347.56,309.47 400.81,362.7 454.05,415.95 457.08,419.02 460.43,421.95 462.46,425.83 465.45,431.73 467.03,438.67 465.14,445.17 463.2,453.74 456.84,461.18 448.63,464.31 442.05,466.87 434.34,466.81 427.88,463.9 421.38,461.28 416.98,455.6 412.07,450.88 360.24,399.05 308.37,347.23 256.58,295.37 255.19,294.59 254.35,296.7 253.42,297.41 201.92,348.91 150.42,400.42 98.92,451.92 94.31,456.42 90.02,461.67 83.83,464.05 74.13,468.23 61.94,466.09 54.47,458.53 49.1,453.57 46.23,446.25 46.02,439.02 46.26,432.03 48.92,424.97 53.92,419.99 108.51,365.39 163.14,310.84 217.68,256.2 202.85,242.07 188.64,227.26 174.05,212.87 134.04,172.88 94.06,132.85 54.04,92.87 48.91,87.63 46.02,80.34 46.03,73.02 46.43,66.1 49.16,59.16 54.26,54.35z"/>
</Style>
</ResourceDictionary>

View File

@@ -0,0 +1,21 @@
<Window x:Class="DellMonitorControl.MainWindow"
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:tb="clr-namespace:Hardcodet.Wpf.TaskbarNotification;assembly=Hardcodet.Wpf.TaskbarNotification.Net6"
xmlns:local="clr-namespace:DellMonitorControl"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Grid>
<tb:TaskbarIcon x:Name="taskbar"
IconSource="/DellLogo.ico"
ToolTipText="調整效能"
PopupActivation="LeftOrDoubleClick">
<tb:TaskbarIcon.TrayPopup>
<local:ControlPanel/>
</tb:TaskbarIcon.TrayPopup>
</tb:TaskbarIcon>
</Grid>
</Window>

View File

@@ -0,0 +1,15 @@
using System.Windows;
namespace DellMonitorControl;
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
this.Hide();
}
}

View File

@@ -0,0 +1,126 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Style x:Key="BaseButton" TargetType="{x:Type ButtonBase}" BasedOn="{x:Null}">
<Setter Property="FocusVisualStyle" Value="{x:Null}" />
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Cursor" Value="Hand" />
<Setter Property="Foreground" Value="{DynamicResource H3}" />
</Trigger>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="Opacity" Value="0.7"/>
</Trigger>
</Style.Triggers>
</Style>
<Style x:Key="TextBorderStyle" TargetType="{x:Type Border}">
<Setter Property="Background" Value="{StaticResource F3}"/>
<Setter Property="BorderBrush" Value="#C1272C"/>
<Setter Property="BorderThickness" Value="0"/>
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="#A12126"/>
</Trigger>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="Opacity" Value="0.3"/>
</Trigger>
</Style.Triggers>
</Style>
<Style x:Key="TextButtonStyle" TargetType="{x:Type Button}" BasedOn="{StaticResource BaseButton}">
<Setter Property="Margin" Value="5"/>
<Setter Property="Width" Value="180"/>
<Setter Property="Height" Value="25"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Border CornerRadius="8" Style="{StaticResource TextBorderStyle}">
<ContentPresenter Margin="2" HorizontalAlignment="Center" VerticalAlignment="Center" RecognizesAccessKey="True"/>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Cursor" Value="Hand" />
<Setter Property="Foreground" Value="{DynamicResource F3}" />
</Trigger>
</Style.Triggers>
</Style>
<Style x:Key="ImageButton" TargetType="{x:Type ButtonBase}" BasedOn="{x:Null}">
<Setter Property="FocusVisualStyle" Value="{x:Null}" />
<Style.Triggers>
<Trigger Property="IsEnabled" Value="false">
<Setter Property="Foreground" Value="{StaticResource DisabledForegroundBrush}"/>
</Trigger>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Cursor" Value="Hand" />
</Trigger>
</Style.Triggers>
</Style>
<Style x:Key="BaseBorderStyle" TargetType="{x:Type Border}">
<Setter Property="Background" Value="{DynamicResource H2}"/>
<Setter Property="BorderBrush" Value="{DynamicResource F3}"/>
<Setter Property="BorderThickness" Value="1"/>
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="{DynamicResource F3}"/>
</Trigger>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="Opacity" Value="0.3"/>
</Trigger>
</Style.Triggers>
</Style>
<Style x:Key="CancelButton" TargetType="{x:Type ButtonBase}" BasedOn="{StaticResource BaseButton}">
<Setter Property="Margin" Value="3,0,0,0"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Border>
<Grid Background="{StaticResource AlphaBrush}">
<Path Style="{DynamicResource PathCancel}" Margin="3"/>
<Path Style="{DynamicResource PathFrame}"/>
</Grid>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="NUDButtonStyle" TargetType="{x:Type RepeatButton}" BasedOn="{x:Null}">
<Setter Property="FocusVisualStyle" Value="{x:Null}" />
<Setter Property="FontSize" Value="20" />
<Setter Property="Foreground" Value="{DynamicResource F3}" />
<Setter Property="FontFamily" Value="Marlett" />
<Setter Property="Width" Value="30" />
<Setter Property="Height" Value="35" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="RepeatButton">
<Border Style="{StaticResource BaseBorderStyle}">
<ContentPresenter Margin="2" HorizontalAlignment="Center" VerticalAlignment="Center" RecognizesAccessKey="True"/>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<Trigger Property="IsEnabled" Value="false">
<Setter Property="Foreground" Value="{StaticResource DisabledForegroundBrush}"/>
</Trigger>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Cursor" Value="Hand" />
<Setter Property="Foreground" Value="{DynamicResource F2}" />
</Trigger>
</Style.Triggers>
</Style>
</ResourceDictionary>

View File

@@ -0,0 +1,37 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Color x:Key="H1Color">#C1272C</Color>
<Color x:Key="H2Color">#66424242</Color>
<Color x:Key="H3Color">#535353</Color>
<Color x:Key="F1Color">#232323</Color>
<Color x:Key="F2Color">#8A3D40</Color>
<Color x:Key="F3Color">#FFFFFF</Color>
<Color x:Key="DisableColor">#B2626262</Color>
<Color x:Key="DisableH2Color">#CCADADAD</Color>
<Color x:Key="NormalGray">#FF686868</Color>
<SolidColorBrush x:Key="NormalForeground" Color="White" />
<SolidColorBrush x:Key="Unexplainable" Color="{StaticResource F2Color}" />
<SolidColorBrush x:Key="Unnecessary" Color="#a08b72" />
<SolidColorBrush x:Key="Selected" Color="{StaticResource H2Color}" />
<SolidColorBrush x:Key="Title" Color="White" />
<SolidColorBrush x:Key="H1" Color="{StaticResource H1Color}" />
<SolidColorBrush x:Key="H2" Color="{StaticResource H2Color}" />
<SolidColorBrush x:Key="H3" Color="{StaticResource H3Color}" />
<SolidColorBrush x:Key="F1" Color="{StaticResource F1Color}" />
<SolidColorBrush x:Key="F2" Color="{StaticResource F2Color}" />
<SolidColorBrush x:Key="F3" Color="{StaticResource F3Color}" />
<SolidColorBrush x:Key="BlurBrush" Color="#CC6C6161" />
<SolidColorBrush x:Key="AlphaBrush" Color="#00FFFFFF" />
<SolidColorBrush x:Key="NormalBrush" Color="{StaticResource NormalGray}" />
<SolidColorBrush x:Key="DisabledForegroundBrush" Color="{StaticResource DisableColor}" />
</ResourceDictionary>

View File

@@ -0,0 +1,58 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:sys="clr-namespace:System;assembly=mscorlib">
<sys:Double x:Key="FontSize">26</sys:Double>
<Style x:Key="TitleStyle" TargetType="{x:Type TextBlock}">
<Setter Property="FocusVisualStyle" Value="{x:Null}" />
<Setter Property="HorizontalAlignment" Value="Center" />
<Setter Property="VerticalAlignment" Value="Center" />
<Setter Property="Background" Value="{x:Null}" />
<Setter Property="Foreground" Value="{DynamicResource F3}" />
<Setter Property="FontSize" Value="{DynamicResource FontSize}" />
<Setter Property="FontWeight" Value="Bold" />
</Style>
<Style x:Key="LableStyle" TargetType="{x:Type TextBlock}" BasedOn="{StaticResource TitleStyle}">
<Setter Property="Foreground" Value="{DynamicResource F3}" />
<Setter Property="FocusVisualStyle" Value="{x:Null}" />
<Setter Property="FontSize" Value="{DynamicResource FontSize}" />
<Setter Property="Margin" Value="10,0,10,0"/>
<Setter Property="HorizontalAlignment" Value="Left" />
<Style.Triggers>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="Opacity" Value="0.40"/>
</Trigger>
</Style.Triggers>
</Style>
<Style x:Key="TextBoxStyle" TargetType="TextBox">
<Setter Property="HorizontalAlignment" Value="Center" />
<Setter Property="VerticalAlignment" Value="Center" />
<Setter Property="TextAlignment" Value="Center" />
<Setter Property="VerticalContentAlignment" Value="Center" />
<Setter Property="MinWidth" Value="60" />
<Setter Property="Foreground" Value="{StaticResource F3}" />
<Setter Property="FontSize" Value="{DynamicResource FontSize}" />
<Setter Property="Margin" Value="0,2,0,2"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type TextBoxBase}">
<Border x:Name="border" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="#33FFFFFF" SnapsToDevicePixels="True">
<ScrollViewer x:Name="PART_ContentHost" Focusable="False" HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Hidden"/>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="Opacity" TargetName="border" Value="0.40"/>
</Trigger>
<Trigger Property="IsFocused" Value="True">
<Setter Property="BorderBrush" Value="{StaticResource DisabledForegroundBrush}"/>
<Setter Property="BorderThickness" Value="2"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>

View File

@@ -0,0 +1,283 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/Style/Color.xaml"/>
</ResourceDictionary.MergedDictionaries>
<Style x:Key="SliderRepeatButton" TargetType="RepeatButton">
<Setter Property="SnapsToDevicePixels" Value="true" />
<Setter Property="OverridesDefaultStyle" Value="true" />
<Setter Property="IsTabStop" Value="false" />
<Setter Property="Focusable" Value="false" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="RepeatButton">
<Border BorderThickness="1" BorderBrush="{x:Null}" Background="#CCB9B6B6" Height="6"/>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="SliderRepeatButton1" TargetType="RepeatButton">
<Setter Property="SnapsToDevicePixels" Value="true" />
<Setter Property="OverridesDefaultStyle" Value="true" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="RepeatButton">
<Border SnapsToDevicePixels="True" BorderThickness="1" Height="6">
<Border.Background>
<LinearGradientBrush EndPoint="1,0" StartPoint="0,0">
<GradientStop Color="{DynamicResource H2Color}"/>
<GradientStop Color="{DynamicResource H3Color}" Offset="1"/>
</LinearGradientBrush>
</Border.Background>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="SliderThumb" TargetType="Thumb">
<Setter Property="SnapsToDevicePixels" Value="true" />
<Setter Property="OverridesDefaultStyle" Value="true" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Thumb">
<Ellipse Height="20" Width="20" Fill="#99FFFFFF"></Ellipse>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<ControlTemplate x:Key="Slider" TargetType="Slider">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto" MinHeight="{TemplateBinding MinHeight}"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Track Grid.Row="1" x:Name="PART_Track">
<Track.DecreaseRepeatButton>
<RepeatButton Style="{StaticResource SliderRepeatButton1}" Command="Slider.DecreaseLarge" />
</Track.DecreaseRepeatButton>
<Track.Thumb>
<Thumb Style="{StaticResource SliderThumb}"/>
</Track.Thumb>
<Track.IncreaseRepeatButton>
<RepeatButton Style="{StaticResource SliderRepeatButton}" Command="Slider.IncreaseLarge" />
</Track.IncreaseRepeatButton>
</Track>
</Grid>
</ControlTemplate>
<Style x:Key="Horizontal_Slider" TargetType="Slider">
<Setter Property="Focusable" Value="False"/>
<Setter Property="SnapsToDevicePixels" Value="true"/>
<Setter Property="OverridesDefaultStyle" Value="true"/>
<Setter Property="HorizontalAlignment" Value="Left"/>
<Setter Property="VerticalAlignment" Value="Center"/>
<Setter Property="Width" Value="300"/>
<Setter Property="Height" Value="25"/>
<Setter Property="Foreground" Value="{x:Null}"/>
<Setter Property="Margin" Value="5,0,10,0"/>
<Style.Triggers>
<Trigger Property="Orientation" Value="Horizontal">
<Setter Property="MinHeight" Value="25"/>
<Setter Property="MinWidth" Value="104"/>
<Setter Property="Template" Value="{StaticResource Slider}"/>
</Trigger>
<Trigger Property="IsEnabled" Value="false">
<Setter Property="Opacity" Value="0.4"/>
</Trigger>
</Style.Triggers>
</Style>
<LinearGradientBrush x:Key="ListBoxBackgroundBrush" StartPoint="0,0" EndPoint="1,0.001">
<GradientBrush.GradientStops>
<GradientStopCollection>
<GradientStop Color="White" Offset="0.0"/>
<GradientStop Color="White" Offset="0.6"/>
<GradientStop Color="#DDDDDD" Offset="1.2"/>
</GradientStopCollection>
</GradientBrush.GradientStops>
</LinearGradientBrush>
<LinearGradientBrush x:Key="StandardBrush" StartPoint="0,0" EndPoint="0,1">
<GradientBrush.GradientStops>
<GradientStopCollection>
<GradientStop Color="#FFF" Offset="0.0"/>
<GradientStop Color="#CCC" Offset="1.0"/>
</GradientStopCollection>
</GradientBrush.GradientStops>
</LinearGradientBrush>
<LinearGradientBrush x:Key="PressedBrush" StartPoint="0,0" EndPoint="0,1">
<GradientBrush.GradientStops>
<GradientStopCollection>
<GradientStop Color="#BBB" Offset="0.0"/>
<GradientStop Color="#EEE" Offset="0.1"/>
<GradientStop Color="#EEE" Offset="0.9"/>
<GradientStop Color="#FFF" Offset="1.0"/>
</GradientStopCollection>
</GradientBrush.GradientStops>
</LinearGradientBrush>
<Style x:Key="ScrollBarBackground" TargetType="{x:Type Border}">
<Setter Property="Margin" Value="2"/>
<Setter Property="CornerRadius" Value="6"/>
<Setter Property="Background" Value="{DynamicResource H2}"/>
<Style.Triggers>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="Background" Value="{x:Null}"/>
</Trigger>
</Style.Triggers>
</Style>
<Style x:Key="ScrollBarLineButton" TargetType="{x:Type RepeatButton}">
<!--上下按鈕 不顯示-->
<Setter Property="Visibility" Value="Hidden"/>
<Setter Property="SnapsToDevicePixels" Value="True"/>
<Setter Property="OverridesDefaultStyle" Value="true"/>
<Setter Property="Focusable" Value="false"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type RepeatButton}">
<Border Name="Border" Margin="1" CornerRadius="2" Background="{DynamicResource H2}" BorderBrush="{DynamicResource H2}" BorderThickness="1">
<Path HorizontalAlignment="Center" VerticalAlignment="Center" Fill="{DynamicResource H2}" Data="{Binding Path=Content, RelativeSource={RelativeSource TemplatedParent}}" />
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsPressed" Value="true">
<Setter TargetName="Border" Property="Background" Value="{StaticResource PressedBrush}" />
</Trigger>
<Trigger Property="IsEnabled" Value="false">
<Setter Property="Foreground" Value="{StaticResource DisabledForegroundBrush}"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="ScrollBarPageButton" TargetType="{x:Type RepeatButton}">
<Setter Property="Visibility" Value="Visible"/>
<Setter Property="SnapsToDevicePixels" Value="True"/>
<Setter Property="OverridesDefaultStyle" Value="true"/>
<Setter Property="IsTabStop" Value="false"/>
<Setter Property="Focusable" Value="false"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type RepeatButton}">
<Border Background="{x:Null}" Margin="1"/>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="ScrollBarThumb" TargetType="{x:Type Thumb}">
<Setter Property="SnapsToDevicePixels" Value="True"/>
<Setter Property="OverridesDefaultStyle" Value="true"/>
<Setter Property="IsTabStop" Value="false"/>
<Setter Property="Focusable" Value="false"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Thumb}">
<Border CornerRadius="4" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="0" Width="7"/>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<ControlTemplate x:Key="VerticalScrollBar" TargetType="{x:Type ScrollBar}">
<Grid>
<Grid.RowDefinitions>
<RowDefinition MaxHeight="5"/>
<RowDefinition Height="0.00001*"/>
<RowDefinition MaxHeight="5"/>
</Grid.RowDefinitions>
<!--直向拉竿背景-->
<Border Grid.RowSpan="4" Style="{StaticResource ScrollBarBackground}"/>
<!--往上按鈕 ※隱藏-->
<RepeatButton Grid.Row="0" Style="{StaticResource ScrollBarLineButton}" Height="18" Command="ScrollBar.LineUpCommand" Content="M 0 4 L 8 4 L 4 0 Z" />
<Track Name="PART_Track" Grid.Row="1" IsDirectionReversed="true" IsEnabled="{TemplateBinding IsMouseOver}" >
<Track.DecreaseRepeatButton>
<RepeatButton Style="{StaticResource ScrollBarPageButton}" Command="ScrollBar.PageUpCommand" />
</Track.DecreaseRepeatButton>
<Track.Thumb>
<Thumb Style="{StaticResource ScrollBarThumb}" Margin="1,0,1,0" Background="{DynamicResource H3}" BorderBrush="{DynamicResource H3}" />
</Track.Thumb>
<Track.IncreaseRepeatButton>
<RepeatButton Style="{StaticResource ScrollBarPageButton}" Command="ScrollBar.PageDownCommand" />
</Track.IncreaseRepeatButton>
</Track>
<!--往下按鈕 ※隱藏-->
<RepeatButton Grid.Row="3" Style="{StaticResource ScrollBarLineButton}" Height="18" Command="ScrollBar.LineDownCommand" Content="M 0 0 L 4 4 L 8 0 Z"/>
</Grid>
</ControlTemplate>
<ControlTemplate x:Key="HorizontalScrollBar" TargetType="{x:Type ScrollBar}">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition MaxWidth="18"/>
<ColumnDefinition Width="0.00001*"/>
<ColumnDefinition MaxWidth="18"/>
</Grid.ColumnDefinitions>
<!--橫向拉竿背景-->
<Border Grid.ColumnSpan="3" CornerRadius="2" Background="{x:Null}"/>
<RepeatButton Grid.Column="0" Style="{StaticResource ScrollBarLineButton}" Width="18" Command="ScrollBar.LineLeftCommand" Content="M 4 0 L 4 8 L 0 4 Z" />
<Track Name="PART_Track" Grid.Column="1" IsDirectionReversed="False">
<Track.DecreaseRepeatButton>
<RepeatButton Style="{StaticResource ScrollBarPageButton}" Command="ScrollBar.PageLeftCommand" />
</Track.DecreaseRepeatButton>
<Track.Thumb>
<Thumb Style="{StaticResource ScrollBarThumb}" Margin="0,1,0,1" Background="{DynamicResource H3}" BorderBrush="{DynamicResource H3}" />
</Track.Thumb>
<Track.IncreaseRepeatButton>
<RepeatButton Style="{StaticResource ScrollBarPageButton}" Command="ScrollBar.PageRightCommand" />
</Track.IncreaseRepeatButton>
</Track>
<RepeatButton Grid.Column="3" Style="{StaticResource ScrollBarLineButton}" Width="18" Command="ScrollBar.LineRightCommand" Content="M 0 0 L 4 4 L 0 8 Z"/>
</Grid>
</ControlTemplate>
<Style x:Key="{x:Type ScrollBar}" TargetType="{x:Type ScrollBar}">
<Setter Property="SnapsToDevicePixels" Value="True"/>
<Setter Property="OverridesDefaultStyle" Value="true"/>
<Style.Triggers>
<Trigger Property="Orientation" Value="Horizontal">
<Setter Property="Width" Value="Auto"/>
<Setter Property="Height" Value="18" />
<Setter Property="Template" Value="{StaticResource HorizontalScrollBar}" />
</Trigger>
<Trigger Property="Orientation" Value="Vertical">
<Setter Property="Width" Value="18"/>
<Setter Property="Height" Value="Auto" />
<Setter Property="Template" Value="{StaticResource VerticalScrollBar}" />
</Trigger>
</Style.Triggers>
</Style>
<Style x:Key="FavsScrollViewer" TargetType="{x:Type ScrollViewer}">
<Setter Property="OverridesDefaultStyle" Value="True"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ScrollViewer}">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<ScrollContentPresenter Grid.Column="1"/>
<ScrollBar Name="PART_VerticalScrollBar" Value="{TemplateBinding VerticalOffset}" Maximum="{TemplateBinding ScrollableHeight}" ViewportSize="{TemplateBinding ViewportHeight}" Visibility="{TemplateBinding ComputedVerticalScrollBarVisibility}"/>
<ScrollBar Name="PART_HorizontalScrollBar" Orientation="Horizontal" Grid.Row="1" Grid.Column="1" Value="{TemplateBinding HorizontalOffset}" Maximum="{TemplateBinding ScrollableWidth}" ViewportSize="{TemplateBinding ViewportWidth}" Visibility="{TemplateBinding ComputedHorizontalScrollBarVisibility}"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>

View File

@@ -1,177 +1,180 @@
using CMM.Library.Base;
using CMM.Library.Helpers;
using CMM.Library.ViewModel;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CMM.Library.Method
namespace CMM.Library.Method;
/// <summary>
/// Control My Monitor Management Command
/// </summary>
public static class CMMCommand
{
/// <summary>
/// Control My Monitor Management Command
/// </summary>
public static class CMMCommand
static readonly string CMMTmpFolder = Path.Combine(Path.GetTempPath(), $"CMM");
static readonly string CMMexe = Path.Combine(CMMTmpFolder, "ControlMyMonitor.exe");
static readonly string CMMsMonitors = Path.Combine(CMMTmpFolder, "smonitors.tmp");
static readonly string CMMcfg = Path.Combine(CMMTmpFolder, "ControlMyMonitor.cfg");
public static async Task ScanMonitor()
{
static readonly string CMMTmpFolder = Path.Combine(Path.GetTempPath(), $"CMM");
static readonly string CMMexe = Path.Combine(CMMTmpFolder, "ControlMyMonitor.exe");
static readonly string CMMsMonitors = Path.Combine(CMMTmpFolder, "smonitors.tmp");
static readonly string CMMcfg = Path.Combine(CMMTmpFolder, "ControlMyMonitor.cfg");
await BytesToFileAsync(new(CMMexe));
await ConsoleHelper.CmdCommandAsync($"{CMMexe} /smonitors {CMMsMonitors}");
}
public static async Task ScanMonitor()
public static async Task PowerOn(string MonitorSn)
{
await ConsoleHelper.CmdCommandAsync($"{CMMexe} /SetValue {MonitorSn} D6 1");
}
public static async Task Sleep(string MonitorSn)
{
await ConsoleHelper.CmdCommandAsync($"{CMMexe} /SetValue {MonitorSn} D6 4");
}
public static async Task ScanMonitorInterfaces(IEnumerable<XMonitor> monitors)
{
var taskList = new List<Task>();
foreach (var mon in monitors)
{
await BytesToFileAsync(new(CMMexe));
await ConsoleHelper.CmdCommandAsync($"{CMMexe} /smonitors {CMMsMonitors}");
taskList.Add(Task.Run(async () => await
ScanMonitorInterfaces($"{CMMTmpFolder}\\{mon.SerialNumber}.tmp", mon)));
}
public static async Task ScanMonitorInterfaces(IEnumerable<XMonitor> monitors)
{
var taskList = new List<Task>();
foreach (var mon in monitors)
{
taskList.Add(Task.Run(async () => await
ScanMonitorInterfaces($"{CMMTmpFolder}\\{mon.SerialNumber}.tmp", mon)));
}
await Task.WhenAll(taskList.ToArray());
}
await Task.WhenAll(taskList.ToArray());
static async Task ScanMonitorInterfaces(string savePath, XMonitor mon)
{
await ConsoleHelper.CmdCommandAsync($"{CMMexe} /scomma {savePath} {mon.MonitorID}");
await mon.ReadMonitorStatus(savePath);
}
/// <summary>
/// 取得螢幕狀態
/// </summary>
public static async Task ReadMonitorStatus(this XMonitor @this, string filePath)
{
var statusColle = new ObservableRangeCollection<XMonitorStatus>();
if (!File.Exists(filePath)) return;
foreach (var line in await File.ReadAllLinesAsync(filePath))
{
var sp = line.Split(",");
if (sp.Length < 6) continue;
statusColle.Add(new XMonitorStatus
{
VCP_Code = StrTrim(sp[0]),
VCPCodeName = StrTrim(sp[1]),
Read_Write = StrTrim(sp[2]),
CurrentValue = TryGetInt(sp[3]),
MaximumValue = TryGetInt(sp[4]),
PossibleValues = TryGetArrStr(sp),
});
}
static async Task ScanMonitorInterfaces(string savePath, XMonitor mon)
@this.Status = statusColle;
string StrTrim(string str)
{
//await ConsoleHelper.CmdCommandAsync($"{CMMexe} /scomma {savePath} {mon.MonitorID}");
await mon.ReadMonitorStatus(savePath);
if (string.IsNullOrEmpty(str)) return null;
return str;
}
/// <summary>
/// 取得螢幕狀態
/// </summary>
public static async Task ReadMonitorStatus(this XMonitor @this, string filePath)
string TryGetArrStr(string[] strArr)
{
var statusColle = new ObservableRangeCollection<XMonitorStatus>();
if (strArr.Length < 7) return null;
if (!File.Exists(filePath)) return;
var outStr = string.Join(",", strArr[5..]);
outStr = outStr.Substring(1, outStr.Length - 2);
return outStr;
}
foreach (var line in await File.ReadAllLinesAsync(filePath))
int? TryGetInt(string str)
{
if (int.TryParse(str, out var value)) return value;
return null;
}
}
/// <summary>
/// 取得螢幕清單
/// </summary>
public static async Task<IEnumerable<XMonitor>> ReadMonitorsData()
{
var monitors = new List<XMonitor>();
if (!File.Exists(CMMsMonitors)) return monitors;
XMonitor mon = null;
string context;
foreach (var line in await File.ReadAllLinesAsync(CMMsMonitors))
{
var sp = line.Split(":", StringSplitOptions.RemoveEmptyEntries);
try
{
var sp = line.Split(",");
if (sp.Length < 6) continue;
statusColle.Add(new XMonitorStatus
{
VCP_Code = StrTrim(sp[0]),
VCPCodeName = StrTrim(sp[1]),
Read_Write = StrTrim(sp[2]),
CurrentValue = TryGetInt(sp[3]),
MaximumValue = TryGetInt(sp[4]),
PossibleValues = TryGetArrStr(sp),
});
if (sp.Length != 2 || string.IsNullOrEmpty(sp[1])) continue;
context = sp[1].Substring(2, sp[1].Length - 3);
}
catch
{
continue;
}
@this.Status = statusColle;
string StrTrim(string str)
if (sp[0].StartsWith("Monitor Device Name"))
{
if (string.IsNullOrEmpty(str)) return null;
return str;
mon = new XMonitor();
mon.MonitorDeviceName = context;
continue;
}
string TryGetArrStr(string[] strArr)
if (sp[0].StartsWith("Monitor Name"))
{
if (strArr.Length < 7) return null;
var outStr = string.Join(",", strArr[5..]);
outStr = outStr.Substring(1, outStr.Length - 2);
return outStr;
mon.MonitorName = context;
continue;
}
int? TryGetInt(string str)
if (sp[0].StartsWith("Serial Number"))
{
if (int.TryParse(str, out var value)) return value;
return null;
mon.SerialNumber = context;
continue;
}
if (sp[0].StartsWith("Adapter Name"))
{
mon.AdapterName = context;
continue;
}
if (sp[0].StartsWith("Monitor ID"))
{
mon.MonitorID = context;
monitors.Add(mon);
continue;
}
}
/// <summary>
/// 取得螢幕清單
/// </summary>
public static async Task<IEnumerable<XMonitor>> ReadMonitorsData()
{
var monitors = new List<XMonitor>();
return monitors;
}
if (!File.Exists(CMMsMonitors)) return monitors;
static void BytesToFile(FileInfo fi)
{
fi.Refresh();
if (fi.Exists) return;
if (!fi.Directory.Exists) fi.Directory.Create();
XMonitor mon = null;
string context;
foreach (var line in await File.ReadAllLinesAsync(CMMsMonitors))
{
var sp = line.Split(":", StringSplitOptions.RemoveEmptyEntries);
try
{
if (sp.Length != 2 || string.IsNullOrEmpty(sp[1])) continue;
File.WriteAllBytes(fi.FullName, fi.Name.ResourceToByteArray());
}
context = sp[1].Substring(2, sp[1].Length - 3);
}
catch
{
continue;
}
if (sp[0].StartsWith("Monitor Device Name"))
{
mon = new XMonitor();
mon.MonitorDeviceName = context;
continue;
}
if (sp[0].StartsWith("Monitor Name"))
{
mon.MonitorName = context;
continue;
}
if (sp[0].StartsWith("Serial Number"))
{
mon.SerialNumber = context;
continue;
}
if (sp[0].StartsWith("Adapter Name"))
{
mon.AdapterName = context;
continue;
}
if (sp[0].StartsWith("Monitor ID"))
{
mon.MonitorID = context;
monitors.Add(mon);
continue;
}
}
return monitors;
}
static void BytesToFile(FileInfo fi)
{
fi.Refresh();
if (fi.Exists) return;
if (!fi.Directory.Exists) fi.Directory.Create();
File.WriteAllBytes(fi.FullName, fi.Name.ResourceToByteArray());
}
static async Task BytesToFileAsync(FileInfo fi)
{
fi.Refresh();
if (fi.Exists) return;
if (!fi.Directory.Exists) fi.Directory.Create();
await File.WriteAllBytesAsync(fi.FullName, fi.Name.ResourceToByteArray());
}
static async Task BytesToFileAsync(FileInfo fi)
{
fi.Refresh();
if (fi.Exists) return;
if (!fi.Directory.Exists) fi.Directory.Create();
await File.WriteAllBytesAsync(fi.FullName, fi.Name.ResourceToByteArray());
}
}