• unity 桌面程序


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

    public class chuantou : MonoBehaviour
    {
    [DllImport(“user32.dll”)]
    public static extern int MessageBox(IntPtr hwnd,string text,string caption,uint type);
    private struct MARGINS
    {
    public int cxLeftWidth;
    public int cxRightWidth;
    public int cxTopHeight;
    public int cxButtomHeight;
    }

    [DllImport("user32.dll")]
    private static extern IntPtr GetActiveWindow();
    [DllImport("Dwmapi.dll")]
    private static extern uint DwmExtendFrameIntoClientArea(IntPtr hWnd,ref MARGINS margins);
    
    [DllImport("user32.dll")] //窗口属性
    private static extern int SetWindowLong(IntPtr hWnd,int nIndex,uint dwNewLong);
    [DllImport("user32.dll",SetLastError =true)] //设置位置置顶
    private static extern int SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags);
    
    [DllImport("user32.dll")]//设置透明层级
    private static extern int SetLayeredWindowAttributes(IntPtr hWnd, uint crKey,byte bAlpha,uint dwFlags);
    
    const int GWL_EXSTYLE = -20;
    const uint WS_EX_LAYERED = 0X00080000;
    const uint WS_EX_TRANSPARENT = 0X00000020;
    
    static readonly IntPtr HWND_TOPMOST=new IntPtr(-1);
    const uint LWA_COLORKEY = 0X00000001;
    
    
    IntPtr hwnd;
    void Start()
    {
    
    
    
         hwnd = GetActiveWindow();
    
        MARGINS margins = new MARGINS { cxLeftWidth = -1 };
        DwmExtendFrameIntoClientArea(hwnd, ref margins);
    
        SetWindowLong(hwnd,GWL_EXSTYLE,WS_EX_LAYERED);
    
        SetLayeredWindowAttributes(hwnd, 0, 0, LWA_COLORKEY);
    
        SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, 0, 0);
    
      
      
    
        Application.runInBackground = true;
    }
    
    // Update is called once per frame
    void Update()
    {
        this.transform.RotateAround(Vector3.zero,new Vector3(0,1,0),0.5f);
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49

    }

  • 相关阅读:
    Go float精度 .00值判断
    C++语言实现网络爬虫详细代码
    中秋节快乐--祝诸佬们今后月来月靓
    试用无线调试器PowerDebugger小记
    JavaSE笔记(八)重制版
    【brpc学习实战二】brpc client构建基本流程
    H5在线CAD,网页CAD,MxDraw云图平台2022.08.24更新
    LLVM学习笔记(62)
    特斯拉Dojo超算:AI训练平台的自动驾驶与通用人工智能之关键
    [pwn基础]动态链接原理
  • 原文地址:https://blog.csdn.net/qq_40390815/article/details/133246386