- Home /
Modifying and displaying the Windows Desktop through Unity Program like VR display?
Hello, I am using a program I found online to let me run Unity and then have a clickable Desktop while Unity runs. This is so I can later modify and add to the desktop from a "background" Unity program. Existing code below.
However I am looking to modify the code to make my first changes: I would like to make the desktop, still clickable, be repeated twice on the left and right side of the screen. From there I would like to add perspective warping to the shape of the displayed desktop, similar to a VR headset. This is because I am looking at running this 'virtual desktop mirror' environment directly on a custom VR device.
Running the code below, here is what I currently see, a regular desktop:
And here is what I would like to see, with the desktop portion visible still clickable:
(excuse the poor image, I tried in paint to replicate what a VR distortion would look like.)
How could I go about doing this? Existing code below -
//Note: Inspired by and uses some code found here: http://forum.unity3d.com/threads/windows-api-calls.127719/
using UnityEngine;
using System.Collections;
using System;
using System.Runtime.InteropServices; // Pro and Free!!!
public class TransparentWindow : MonoBehaviour
{
[DllImport("user32.dll", EntryPoint = "MoveWindow")]
static extern int MoveWindow(int hwnd, int x, int y, int nWidth, int nHeight, int bRepaint);
[DllImport("user32.dll", EntryPoint = "SetWindowLongA")]
static extern int SetWindowLong(int hwnd, int nIndex, long dwNewLong);
[DllImport("user32.dll")]
static extern bool ShowWindowAsync(int hWnd, int nCmdShow);
[DllImport("user32.dll", EntryPoint = "SetLayeredWindowAttributes")]
static extern int SetLayeredWindowAttributes(int hwnd, int crKey, byte bAlpha, int dwFlags);
[DllImport("user32.dll", EntryPoint = "GetActiveWindow")]
private static extern int GetActiveWindow();
[DllImport("user32.dll", EntryPoint = "GetWindowLong")]
private static extern long GetWindowLong(int hwnd, int nIndex);
[DllImport("user32.dll", EntryPoint = "GetSystemMetrics")]
private static extern int GetSystemMetrics(int nIndex);
[DllImport("user32.dll", EntryPoint = "SetWindowPos")]
private static extern int SetWindowPos(int hwnd, int hwndInsertAfter, int x, int y, int cx, int cy, int uFlags);
void Start()
{
int handle = GetActiveWindow();
int fWidth = Screen.width ;
int fHeight = Screen.height;
MoveWindow(handle, 0, 0, fWidth, fHeight, 1); // move the Unity Project windows >>> 0,0
ShowWindowAsync(handle, 3); // full screen !!! // SW_SHOWMAXIMIZED
//Remove title bar
long lCurStyle = GetWindowLong(handle, -16); // GWL_STYLE=-16
int a = 12582912; //WS_CAPTION = 0x00C00000L
int b = 1048576; //WS_HSCROLL = 0x00100000L
int c = 16777216; //WS_MAXIMIZE = 0x01000000L
int d = 524288; //WS_SYSMENU = 0x00080000L
int e = 2097152; //WS_VSCROLL = 0x00200000L
lCurStyle -= a | b | c | d | e;
SetWindowLong(handle, -16, lCurStyle);//524288); // GWL_EXSTYLE=-20 , WS_EX_LAYERED=524288=&h80000
lCurStyle = GetWindowLong(handle, -20);
int j = 1; //WS_EX_DLGMODALFRAME = 0x00000001L
int k = 512; //WS_EX_CLIENTEDGE = 0x00000200L
int l = 131072; //WS_EX_STATICEDGE = 0x00020000L
lCurStyle -= j | k | l;
// Transparency windows
SetWindowLong(handle, -20, lCurStyle);//524288); // GWL_EXSTYLE=-20 , WS_EX_LAYERED=524288=&h80000
//SetLayeredWindowAttributes(handle,0,127, 2); // Transparency=127 >> 50% , LWA_ALPHA=2
// Transparency color key !!!
SetLayeredWindowAttributes(handle, 0, 0, 1); // handle,color key = 0 >> black, % of transparency, LWA_COLORKEY=1
//SetWindowPos(Handle, HWND_TOP, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN), SWP_FRAMECHANGED | SWP_SHOWWINDOW);
//SWP_FRAMECHANGED = 0x0020
//SWP_SHOWWINDOW = 0x0040
SetWindowPos(handle, 0, 0, 0, GetSystemMetrics(0), GetSystemMetrics(1), 32 | 64); //handle,0,0
}
}
Thank you very much in advance for any help!