-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTransparentWindow.cs
More file actions
63 lines (47 loc) · 1.95 KB
/
TransparentWindow.cs
File metadata and controls
63 lines (47 loc) · 1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
using System.Runtime.InteropServices;
public class TransparentWindow : MonoBehaviour
{
[DllImport("user32.dll")]
public static extern int MessageBox(IntPtr hWnd, string text, string caption, uint type);
[DllImport("user32.dll")]
private static extern IntPtr GetActiveWindow();
[DllImport("user32.dll")]
private static extern int SetWindowLong(IntPtr hWnd, int nIndex, uint dwNewLong);
[DllImport("user32.dll")]
static extern int SetLayeredWindowAttributes(IntPtr hwnd, uint crKey, byte bAlpha, uint dwFlags);
[DllImport("user32.dll")]
static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags);
private struct MARGINS
{
public int cxLeftWidth;
public int cdRightWidth;
public int cyTopHeight;
public int cyBottomHeight;
}
[DllImport("Dwmapi.dll")]
private static extern uint DwmExtendFrameIntoClientArea(IntPtr hWnd, ref MARGINS margins);
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;
public void Start()
#if !UNITY_EDITOR_
{
//MessageBox(new IntPtr(0), "Hello World!", "Hello Dialog", 0);
IntPtr hWnd = GetActiveWindow();
MARGINS margins = new MARGINS { cxLeftWidth = -1};
DwmExtendFrameIntoClientArea(hWnd, ref margins);
//unlock the window to interact with the os
SetWindowLong(hWnd, GWL_EXSTYLE, WS_EX_LAYERED);//| WS_EX_TRANSPARENT);
SetLayeredWindowAttributes(hWnd, 0, 0, LWA_COLORKEY);
//hWnd window handle
SetWindowPos(hWnd, HWND_TOPMOST, 0, 0, 0, 0, 0);
#endif
Application.runInBackground = true;
}
}