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

}

相关推荐
向宇it22 分钟前
【unity组件介绍】URP Decal Projector贴花投影器,将特定材质(贴花)投影到场景中的其他对象上。
游戏·3d·unity·c#·游戏引擎·材质
快乐觉主吖11 小时前
Unity网络通信的插件分享,及TCP粘包分包问题处理
tcp/ip·unity·游戏引擎
erxij2 天前
【游戏引擎之路】登神长阶(十八):3天制作Galgame引擎《Galplayer》——无敌之道心
游戏引擎
lizz312 天前
GAMES101 lec2-数学基础1(线性代数)
线性代数·游戏引擎·图形渲染
啊基米德2 天前
lua(xlua)基础知识点记录一
unity·lua·xlua
夜色。2 天前
Unity Android Logcat插件 输出日志中文乱码解决
android·unity
X-mj2 天前
Unity URP + XR 自定义 Skybox 在真机变黑问题全解析与解决方案(支持 Pico、Quest 等一体机)
unity·游戏引擎·xr
erxij2 天前
【游戏引擎之路】登神长阶(十七):Humanoid动画——长风破浪会有时,直挂云帆济沧海
游戏引擎
erxij2 天前
【游戏引擎之路】登神长阶(十九):3D物理引擎——岁不寒,无以知松柏;事不难,无以知君子
3d·游戏引擎
心疼你的一切2 天前
Unity 多人游戏框架学习系列一
学习·游戏·unity·c#·游戏引擎