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

}

相关推荐
yi碗汤园6 小时前
【超详细】C#自定义工具类-StringHelper
开发语言·前端·unity·c#·游戏引擎
野奔在山外的猫8 小时前
【案例】Unity 平台访问文件浏览器(汇总)
unity
WaWaJie_Ngen17 小时前
【OpenGL】模板测试(StencilTest)
c++·算法·游戏·游戏引擎·游戏程序·图形渲染
开发游戏的老王1 天前
虚幻引擎虚拟制片入门教程目录
游戏引擎·虚幻
future_studio2 天前
聊聊 Unity(小白专享、C# 小程序 之 自动更新)
unity·小程序·c#
心疼你的一切2 天前
Unity开发利器:ScriptableObject的数据容器设计与内存优化原理
microsoft·unity·c#·游戏引擎
至善迎风2 天前
将跨平台框架或游戏引擎开发的 Windows 应用上架 Microsoft Store
windows·microsoft·游戏引擎
worxfr2 天前
小游戏引擎架构设计案例分析
游戏引擎
Cool-浩2 天前
【征文计划】Rokid 语音指令开发教程 【包含工程源码 和体验包APK】
unity·ar·语音识别·rokid·语音指令
Brianna Home2 天前
从零到一:用Godot打造2D游戏《丛林探险》
算法·游戏·性能优化·游戏引擎·bug·godot·动画