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

}

相关推荐
冰凌糕8 小时前
Unity3D 单例模式
unity
Artistation Game2 天前
九、怪物行为逻辑
游戏·unity·游戏引擎
百里香酚兰2 天前
【AI学习笔记】基于Unity+DeepSeek开发的一些BUG记录&解决方案
人工智能·学习·unity·大模型·deepseek
妙为2 天前
unreal engine5制作动作类游戏时,我们使用刀剑等武器攻击怪物或敌方单位时,发现攻击特效、伤害等没有触发
游戏·游戏引擎·虚幻·碰撞预设
dangoxiba2 天前
[Unity Demo]从零开始制作空洞骑士Hollow Knight第十三集:制作小骑士的接触地刺复活机制以及完善地图的可交互对象
游戏·unity·visualstudio·c#·游戏引擎
先生沉默先3 天前
使用Materialize制作unity的贴图,Materialize的简单教程,Materialize学习日志
学习·unity·贴图
十画_8243 天前
Visual Studio 小技巧记录
unity·visual studio
red_redemption3 天前
cpp,git,unity学习
git·unity·游戏引擎
tealcwu3 天前
【Unity踩坑】Unity更新Google Play结算库
unity·游戏引擎
先生沉默先3 天前
unity 默认渲染管线材质球的材质通道,材质球的材质通道
unity·游戏引擎·材质