12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- using System;
- using System.Runtime.InteropServices;
- using System.Windows;
- using System.Windows.Interop;
- namespace BarrageTransporter
- {
- /// <summary>
- /// BarrageCurtainWindow.xaml 的交互逻辑
- /// </summary>
- public partial class BarrageCurtainWindow : Window
- {
- public double screenHeight = SystemParameters.PrimaryScreenHeight;
- public double screenWidth = SystemParameters.PrimaryScreenWidth;
- private BarrageManager barrageManager = null;
- public BarrageCurtainWindow()
- {
- InitializeComponent();
- Top = 0;
- Left = 0;
- Width = screenWidth;
- Height = screenHeight;
- }
- /// <summary>
- /// Window penetration
- /// </summary>
- protected override void OnSourceInitialized(EventArgs e)
- {
- base.OnSourceInitialized(e);
- var hwnd = new WindowInteropHelper(this).Handle;
- WindowsServices.SetWindowExTransparent(hwnd);
- }
- public void Shoot(string text)
- {
- if (barrageManager == null)
- {
- barrageManager = new BarrageManager(curtain);
- }
- barrageManager.Shoot(text);
- }
- public int BarrageCount
- {
- get
- {
- if (barrageManager == null)
- {
- return 0;
- }
- else
- {
- return barrageManager.BarrageCount;
- }
- }
- }
- }
- /// <summary>
- /// Window penetration
- /// </summary>
- public static class WindowsServices
- {
- const int WS_EX_TRANSPARENT = 0x00000020;
- const int GWL_EXSTYLE = (-20);
- [DllImport("user32.dll")]
- static extern int GetWindowLong(IntPtr hwnd, int index);
- [DllImport("user32.dll")]
- static extern int SetWindowLong(IntPtr hwnd, int index, int newStyle);
- public static void SetWindowExTransparent(IntPtr hwnd)
- {
- var extendedStyle = GetWindowLong(hwnd, GWL_EXSTYLE);
- SetWindowLong(hwnd, GWL_EXSTYLE, extendedStyle | WS_EX_TRANSPARENT);
- }
- }
- }
|