You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

93 lines
2.6 KiB

using EC.Util.CameraSDK;
using System;
using System.Runtime.InteropServices;
using System.Windows;
using System.Windows.Interop;
namespace JiLinApp.Components;
/// <summary>
/// CameraRealPlay.xaml 的交互逻辑
/// </summary>
public partial class CameraRealPlay : Window
{
#region
private ICameraSDK CameraSdk { get; }
#endregion
public CameraRealPlay(ICameraSDK cameraSdk)
{
InitializeComponent();
CameraSdk = cameraSdk;
}
#region Base
public void StartPlay()
{
IntPtr hwnd = ((HwndSource)PresentationSource.FromVisual(player)).Handle;
CameraSdk.StartPlay(hwnd);
}
public void StopPlay()
{
CameraSdk.StopPlay();
}
#endregion
private const int GWL_STYLE = -16;
private const int WS_MAXIMIZEBOX = 0x10000;
private const int WS_MINIMIZEBOX = 0x20000;
private const int SWP_NOSIZE = 0x0001;
private const int SWP_NOMOVE = 0x0002;
private const int SWP_NOZORDER = 0x0004;
private const int SWP_FRAMECHANGED = 0x0020;
[DllImport("user32.dll", EntryPoint = "GetWindowLong", CharSet = CharSet.Auto)]
private static extern int GetWindowLong32(IntPtr hWnd, int nIndex);
[DllImport("user32.dll")]
private static extern int GetWindowLongPtr(IntPtr hwnd, int index);
[DllImport("user32.dll", EntryPoint = "SetWindowLong", CharSet = CharSet.Auto)]
private static extern int SetWindowLong32(IntPtr hwnd, int index, int value);
[DllImport("user32.dll")]
private static extern int SetWindowLongPtr(IntPtr hwnd, int index, int value);
[DllImport("user32.dll")]
private static extern bool SetWindowPos(IntPtr hWnd, int hWndInsertAfter, int x, int Y, int cx, int cy, int wFlags);
#region Util
public void HideMinButton()
{
IntPtr hwnd = new WindowInteropHelper(this).Handle;
if (IntPtr.Size == 4)
{
var currentStyle = GetWindowLong32(hwnd, GWL_STYLE);
_ = SetWindowLong32(hwnd, GWL_STYLE, (currentStyle & ~WS_MINIMIZEBOX));
}
else
{
var currentStyle = GetWindowLongPtr(hwnd, GWL_STYLE);
_ = SetWindowLongPtr(hwnd, GWL_STYLE, (currentStyle & ~WS_MINIMIZEBOX));
}
//call SetWindowPos to make sure the SetWindowLongPtr take effect according to MSDN
SetWindowPos(hwnd, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER | SWP_FRAMECHANGED);
}
public bool IsClosed { get; private set; }
protected override void OnClosed(EventArgs e)
{
base.OnClosed(e);
IsClosed = true;
StopPlay();
}
#endregion
}