using System;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using UnityEngine;

/// <summary>
/// 设置camera solid camera ,(0,0,0,0)
/// 关闭project setting中USE DXGI flip mode
/// 注意事项：
/// 1，如果是build-in pipeline,要把camera的HDR关闭
/// 2，URP pipeline，关闭HDR，关闭postprocess
/// </summary>

public class TransparancyManager : MonoBehaviour
{
    [DllImport("user32.dll")]
    static extern int MessageBox(IntPtr hwnd, string text,string caption,uint type);

    [StructLayout(LayoutKind.Sequential)]
    public struct MARGINS
    {
        public int cxLeftWidth;
        public int cxRightWidth;
        public int cyTopHeight;
        public int cyBottomHeight;
    }
    
    [DllImport("Dwmapi.dll")]
    static extern uint DwmExtendFrameIntoClientArea(IntPtr hwnd, ref MARGINS margins);

    [DllImport("user32.dll")]
    static extern IntPtr GetActiveWindow();

    [DllImport("user32.dll")]
    static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);

    [DllImport("user32.dll", SetLastError = true)]
    static extern int GetWindowLong(IntPtr hWnd, int nIndex);

    [DllImport("user32.dll")]
    static extern bool SetLayeredWindowAttributes(IntPtr hwnd, uint crKey, byte bAlpha, uint dwFlags);

    const int GWL_EXSTYLE = -20;
    const int WS_EX_LAYERED = 0x80000;
    const int LWA_COLORKEY = 0x1;
    const int LWA_ALPHA = 0x2;


    void Update()
    {

        //IntPtr Hwnd = GetActiveWindow();
        //MARGINS margins = new MARGINS{cxLeftWidth = -1};
 
        IntPtr hwnd = GetActiveWindow();
        SetWindowLong(hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) | WS_EX_LAYERED);
        SetLayeredWindowAttributes(hwnd, 0, 255, LWA_COLORKEY); // You might not need LWA_COLORKEY

    }
}