88 lines
2.4 KiB
C#
88 lines
2.4 KiB
C#
using CMM.Library.WinAPI;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Runtime.InteropServices;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using System.Windows.Data;
|
|
using System.Windows.Documents;
|
|
using System.Windows.Input;
|
|
using System.Windows.Interop;
|
|
using System.Windows.Media;
|
|
using System.Windows.Media.Imaging;
|
|
using System.Windows.Navigation;
|
|
using System.Windows.Shapes;
|
|
|
|
namespace CMM.Management
|
|
{
|
|
/// <summary>
|
|
/// Interaction logic for MainWindow.xaml
|
|
/// </summary>
|
|
public partial class MainWindow : Window
|
|
{
|
|
public MainWindow()
|
|
{
|
|
InitializeComponent();
|
|
|
|
}
|
|
|
|
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
private void Window_Loaded(object sender, RoutedEventArgs e)
|
|
{
|
|
EnableBlur();
|
|
this.DataContext = App.CMMMgr;
|
|
}
|
|
|
|
#region 透明背景
|
|
private void EnableBlur()
|
|
{
|
|
var windowHelper = new WindowInteropHelper(this);
|
|
var accent = new AccentPolicy();
|
|
accent.AccentState = AccentState.ACCENT_ENABLE_BLURBEHIND;
|
|
var accentStructSize = Marshal.SizeOf(accent);
|
|
var accentPtr = Marshal.AllocHGlobal(accentStructSize);
|
|
Marshal.StructureToPtr(accent, accentPtr, false);
|
|
var data = new WindowCompositionAttributeData();
|
|
data.Attribute = WindowCompositionAttribute.WCA_ACCENT_POLICY;
|
|
data.SizeOfData = accentStructSize;
|
|
data.Data = accentPtr;
|
|
|
|
Win32.SetWindowCompositionAttribute(windowHelper.Handle, ref data);
|
|
|
|
Marshal.FreeHGlobal(accentPtr);
|
|
}
|
|
#endregion
|
|
|
|
private void move(object sender, MouseButtonEventArgs e) => DragMove();
|
|
|
|
private void Btn_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
var tag = (sender as FrameworkElement).Tag.ToString();
|
|
|
|
switch (tag)
|
|
{
|
|
case "Exit":
|
|
Deconstruct();
|
|
break;
|
|
case "Minimized":
|
|
this.WindowState = WindowState.Minimized;
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
private void Deconstruct()
|
|
{
|
|
Environment.Exit(0);
|
|
}
|
|
}
|
|
}
|