Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by iiJDSii · Feb 25, 2020 at 10:19 PM · vrwindows

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:

alt text

And here is what I would like to see, with the desktop portion visible still clickable:

alt text (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!

unityq1.jpg (308.8 kB)
unityq2.jpg (302.3 kB)
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

156 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Build Standalone (.exe) with google cardboard VR. 1 Answer

What can we do to allow the Universal Windows Platform to accept the framework from a plugin’s rejected scripts? 1 Answer

,Cursor is always in LOADING state (InputSystem 1.0.0, Win10 standalone + Legacy VR) 0 Answers

Disable Windows Mixed Reality headset rotation/position tracking 1 Answer

Enabling VR at runtime does not enable VR controllers 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges