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);
}

}

相关推荐
电子云与长程纠缠2 小时前
Godot学习05 - 播放与分离FBX动画
学习·游戏引擎·godot
小贺儿开发3 小时前
【Arduino与Unity交互探究】03 超声波测距模块
unity·arduino·串口通信·传感器·videoplayer·硬件交互
weixin_409383125 小时前
godot等轴视角tilemaplayer的学习 isocheric的素材xy大小怎么调
学习·游戏引擎·godot
WarrenMondeville9 小时前
1.Unity面向对象-单一职责原则
unity·设计模式·c#
WarrenMondeville9 小时前
2.Unity面向对象- 开闭原则
unity·游戏引擎·开闭原则
呆呆敲代码的小Y10 小时前
UnityMCP+Claude+VSCode,构建最强AI游戏开发环境
人工智能·vscode·游戏·unity·游戏引擎·u3d·mcp
C蔡博士10 小时前
Unity TextMeshPro 中文本地化:动态生成最小字体集(解决边缘模糊、乱码问题)
unity·游戏引擎
m0_6301824610 小时前
Unity TMP 中文字体生成
unity·游戏引擎
weixin_4093831210 小时前
godot y排序定位 sprite原点 等轴视角地图块测试 isometric 碰撞测试 初学godot
游戏引擎·godot
万兴丶11 小时前
Unity用C#完成抖音小游戏接入引力引擎(Gravity Engine)完整指南,一篇文章讲清楚!
unity·c#·游戏引擎·抖音