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

}

相关推荐
tealcwu3 小时前
【Unity踩坑】Unity中父对象是非均匀缩放时出现倾斜或剪切现象
unity·游戏引擎
Little丶Seven4 小时前
Unity UGUI原理剖析
ui·unity·图形渲染
你疯了抱抱我7 小时前
【VRChat 改模】开发环境搭建:VCC、VRChat SDK、Unity 等环境配置
unity·游戏引擎·vr·vrchat
虾球xz1 天前
游戏引擎学习第23天
学习·游戏引擎
峰度偏偏1 天前
【适配】屏幕拖拽-滑动手感在不同分辨率下的机型适配
算法·游戏·unity·ue5·ue4·godot
虾球xz1 天前
游戏引擎学习第24天
学习·游戏引擎
小春熙子2 天前
Unity图形学之CubeMap立方体贴图
unity·游戏引擎·贴图·技术美术
浅陌sss2 天前
Unity中动态生成贴图并保存成png图片实现
unity·游戏引擎·贴图
小春熙子2 天前
Unity图形学之法线贴图原理
unity·游戏引擎·贴图·技术美术
Miguel Pan2 天前
虚幻引擎---初识篇
游戏引擎·虚幻