using Microsoft.Win32; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Controls.Primitives; using System.Windows.Media; namespace ECMonitor.PlayerDraw.Code { public enum ColorEnum { 绿色, 黄色, 红色, 白色, 青色, 蓝色, 紫色, 黑色, 灰色, 橙色 } /// /// 表示部分音频文件的类型 /// public enum FileTypes { MKV = 2669, MP4 = 00, INI = 255254, MP3 = 7368, WAV = 8273, WMA = 4838, AVI = 8273, WMV = 4838, } public class BlackboardClass { /// /// 初始化BlackboardClass /// public BlackboardClass() { } /// /// 添加或删除启动项 /// /// true为添加启动项,否则为删除启动项 /// 启动项的名称 /// 要开机启动的应用程序的exe文件的路径 /// 表示是否完成添加或删除任务 public static bool RunItem(bool isStart, string startName, string applicationPath) { bool result = true; RegistryKey HKLM = Registry.CurrentUser; RegistryKey run = HKLM.CreateSubKey(@"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run\"); if (isStart) { try { run.SetValue(startName, applicationPath); HKLM.Close(); } catch (Exception) { } } else { try { run.DeleteValue(startName); HKLM.Close(); } catch (Exception) { } } result = run.GetValue("智能版") != null; HKLM.Close(); return result; } /// /// 初始化BlackboardClass /// /// 要移动的控件 public BlackboardClass(UserControl moveControl) { MoveControl = moveControl; } /// /// 要移动的控件 /// public UserControl MoveControl { get; set; } /// /// 提供一个Thumb在Grid上的DragDelta处理程序 /// /// /// public void ThumbMove(object sender, System.Windows.Controls.Primitives.DragDeltaEventArgs e) { if (MoveControl != null) { double top = MoveControl.Margin.Top + e.VerticalChange,//上边距 left = MoveControl.Margin.Left + e.HorizontalChange;//左边距 MoveControl.Margin = new System.Windows.Thickness(left, top, 0, 0); } } public static bool IsAudio(string path) { FileStream fileStream = new FileStream(path, FileMode.Open, FileAccess.Read); BinaryReader read = new BinaryReader(fileStream); byte code; string fileTypeCode = String.Empty; try { for (int i = 0; i < 2; i++) { code = read.ReadByte(); fileTypeCode += code.ToString(); } } catch (Exception) { return false; } fileStream.Close(); read.Close(); int tryVal; return !Int32.TryParse(((FileTypes)Enum.Parse(typeof(FileTypes), fileTypeCode)).ToString(), out tryVal); } /// /// 改变颜色 /// /// 要返回的颜色 public static Color ChangeColor(ColorEnum color) { switch (color) { case ColorEnum.白色: return Colors.White; case ColorEnum.黄色: return Colors.Yellow; case ColorEnum.黑色: return Colors.Black; case ColorEnum.红色: return Colors.Red; case ColorEnum.灰色: return Colors.Gray; case ColorEnum.蓝色: return Colors.Blue; case ColorEnum.绿色: return Colors.Green; case ColorEnum.青色: return Colors.Cyan; case ColorEnum.紫色: return Colors.Purple; case ColorEnum.橙色: return Colors.Orange; default: return new Color(); } } public void ChangSize(object sender, System.Windows.Controls.Primitives.DragDeltaEventArgs e) { double wibth = this.MoveControl.ActualWidth; double heigth = this.MoveControl.ActualHeight; switch ((sender as Thumb).Name) { case "LeftTop": double left = MoveControl.Margin.Left, top = MoveControl.Margin.Top; if (MoveControl.ActualWidth - e.HorizontalChange <= this.MoveControl.MaxWidth && MoveControl.ActualWidth - e.HorizontalChange >= this.MoveControl.MinWidth) { wibth = MoveControl.ActualWidth - e.HorizontalChange; left = MoveControl.Margin.Left + e.HorizontalChange; } if (MoveControl.ActualHeight - e.VerticalChange <= this.MoveControl.MaxHeight && MoveControl.ActualHeight - e.VerticalChange >= this.MoveControl.MinHeight) { heigth = MoveControl.ActualHeight - e.VerticalChange; top = MoveControl.Margin.Top + e.VerticalChange; } MoveControl.Margin = new Thickness(left, top, 0, 0); break; case "LeftBottom": left = this.MoveControl.Margin.Left; double bottom = this.MoveControl.Margin.Bottom; if (MoveControl.ActualWidth - e.HorizontalChange <= this.MoveControl.MaxWidth && MoveControl.ActualWidth - e.HorizontalChange >= this.MoveControl.MinWidth) { wibth = MoveControl.ActualWidth - e.HorizontalChange; left = MoveControl.Margin.Left + e.HorizontalChange; } if (MoveControl.ActualHeight + e.VerticalChange <= this.MoveControl.MaxHeight && MoveControl.ActualHeight + e.VerticalChange >= this.MoveControl.MinHeight) { heigth = MoveControl.ActualHeight + e.VerticalChange; bottom = MoveControl.Margin.Bottom - e.VerticalChange; } MoveControl.Margin = new Thickness(left, MoveControl.Margin.Top, 0, bottom); break; case "RightTop": top = this.MoveControl.Margin.Top; if (MoveControl.ActualWidth + e.HorizontalChange <= this.MoveControl.MaxWidth && MoveControl.ActualWidth + e.HorizontalChange >= this.MoveControl.MinWidth) wibth = MoveControl.ActualWidth + e.HorizontalChange; if (MoveControl.ActualHeight - e.VerticalChange <= this.MoveControl.MaxHeight && MoveControl.ActualHeight - e.VerticalChange >= this.MoveControl.MinHeight) { heigth = MoveControl.ActualHeight - e.VerticalChange; top = MoveControl.Margin.Top + e.VerticalChange; } MoveControl.Margin = new Thickness(MoveControl.Margin.Left, top, 0, MoveControl.Margin.Bottom); break; default: double right = this.MoveControl.Margin.Right; bottom = this.MoveControl.Margin.Bottom; if (MoveControl.ActualWidth + e.HorizontalChange <= this.MoveControl.MaxWidth && MoveControl.ActualWidth + e.HorizontalChange >= this.MoveControl.MinWidth) { wibth = MoveControl.ActualWidth + e.HorizontalChange; right = MoveControl.Margin.Right - e.HorizontalChange; } if (MoveControl.ActualHeight + e.VerticalChange <= this.MoveControl.MaxHeight && MoveControl.ActualHeight + e.VerticalChange >= this.MoveControl.MinHeight) { heigth = MoveControl.ActualHeight + e.VerticalChange; bottom = this.MoveControl.Margin.Bottom - e.VerticalChange; } MoveControl.Margin = new Thickness(MoveControl.Margin.Left, MoveControl.Margin.Top, right, bottom); break; } MoveControl.Width = wibth; MoveControl.Height = heigth; } } }