Beispiel #1
0
    /// <summary>
    /// Move rePaper to corresponding display.
    /// </summary>
    public void MoveToDisplay(int i)
    {
        StaticPinvoke.RECT appBounds_;
        Rectangle          screenBounds_;

        Screen[] screens = Screen.AllScreens;

        if (i > (screens.Length - 1))
        {
            i = 0; //primary monitor
        }
        StaticPinvoke.GetWindowRect(workerw, out appBounds_);
        screenBounds_ = System.Windows.Forms.Screen.FromHandle(workerw).Bounds;
        //force refresh desktop
        StaticPinvoke.SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, null, SPIF_UPDATEINIFILE);

        if (i == -1)
        {
            //crash, skipping for now.
            //StaticPinvoke.SetWindowPos(old_unity_handle, 1, appBounds_.Left, appBounds_.Top, screens[i].Bounds.Width, screens[i].Bounds.Height, 0);
        }
        else
        {
            // adding the workerw offsets to x & y. (basically the bounds change since rePaper is a child of workerw handle)
            StaticPinvoke.SetWindowPos(old_unity_handle, 1, screens[i].Bounds.X - appBounds_.Left, screens[i].Bounds.Y - appBounds_.Top, screens[i].Bounds.Width, screens[i].Bounds.Height, 0);
        }
    }
Beispiel #2
0
 /// <summary>
 /// Sets desktop wallpaper to user selected image in filebrowser.
 /// </summary>
 /// <param name="filePath">wallpaper path.</param>
 public void SetCustomWallpaper(string filePath)
 {
     if (filePath != null)
     {
         StaticPinvoke.SystemParametersInfo(SPI_SETDESKWALLPAPER, (UInt32)filePath.Length, filePath, SPIF_UPDATEINIFILE | SPIF_SENDWININICHANGE);
     }
 }
Beispiel #3
0
    /// <summary>
    /// Retrieves windows desktop wallpaper & loads it.
    /// </summary>
    public void GetWallpaperImage()
    {
        RegistryKey currentMachine = Registry.CurrentUser;
        RegistryKey controlPanel   = currentMachine.OpenSubKey("Control Panel");
        RegistryKey desktop        = controlPanel.OpenSubKey("Desktop");

        string filePath = Convert.ToString(desktop.GetValue("WallPaper"));

        controlPanel.Close();

        if (!System.IO.File.Exists(filePath))
        {
            //Try to retrieve wallpaper image with cached file..
            filePath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\Microsoft\\Windows\\Themes\\CachedFiles";
            if (Directory.Exists(filePath))
            {
                string[] filePaths = Directory.GetFiles(filePath);
                if (filePaths.Length > 0)
                {
                    filePath = filePaths[0];
                }
            }
            else
            {
                //Try to retrieve wallpaper image by original source..
                RegistryKey regKey = Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Internet Explorer\\Desktop\\General\\", false);
                filePath = regKey.GetValue("WallpaperSource").ToString() + "h";
                if (!System.IO.File.Exists(filePath))
                {
                    //Failed to retrieve wallpaper image by original source..
                    filePath = new String('\0', MAX_PATH);
                    StaticPinvoke.SystemParametersInfo(SPI_GETDESKWALLPAPER, (UInt32)filePath.Length, filePath, 0);
                    filePath = filePath.Substring(0, filePath.IndexOf('\0'));
                }
            }
        }

        if (System.IO.File.Exists(filePath))
        {
            MenuController.menuController.wallpaperPath = filePath;
            tex = new Texture2D(2, 2);
            StartCoroutine(WaitForImageDownload(filePath)); //async image loading.
        }
        else
        {
            UnityEngine.Debug.Log("Failed to retrieve wallpaper image using all methods!");
        }

        desktop.Close();
        currentMachine.Close();
    }
Beispiel #4
0
    /// <summary>
    /// Retrieves current wallpaper path, including name.
    /// </summary>
    /// <returns>
    /// Wallpaper path string.
    /// </returns>
    public static string GetWallpaperImagePath()
    {
        RegistryKey currentMachine = Registry.CurrentUser;
        RegistryKey controlPanel   = currentMachine.OpenSubKey("Control Panel");
        RegistryKey desktop        = controlPanel.OpenSubKey("Desktop");

        string filePath = Convert.ToString(desktop.GetValue("WallPaper"));

        controlPanel.Close();

        if (!System.IO.File.Exists(filePath))
        {
            filePath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\Microsoft\\Windows\\Themes\\CachedFiles";
            if (Directory.Exists(filePath))
            {
                string[] filePaths = Directory.GetFiles(filePath);
                if (filePaths.Length > 0)
                {
                    filePath = filePaths[0];
                }
            }
            else
            {
                RegistryKey regKey = Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Internet Explorer\\Desktop\\General\\", false);
                filePath = regKey.GetValue("WallpaperSource").ToString() + "h";
                if (!System.IO.File.Exists(filePath))
                {
                    filePath = new String('\0', MAX_PATH);
                    StaticPinvoke.SystemParametersInfo(SPI_GETDESKWALLPAPER, (UInt32)filePath.Length, filePath, 0);
                    filePath = filePath.Substring(0, filePath.IndexOf('\0'));
                }
            }
        }

        desktop.Close();
        currentMachine.Close();

        if (System.IO.File.Exists(filePath))
        {
            //UnityEngine.Debug.Log(filePath);
            return(filePath);
        }
        else
        {
            UnityEngine.Debug.LogError("Failed to retrieve wallpaper image using all methods!");
            return(null);
        }
    }
Beispiel #5
0
 /// <summary>
 /// Force refresh desktop.
 /// </summary>
 void SetWallpaper()
 {
     StaticPinvoke.SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, null, SPIF_UPDATEINIFILE | SPIF_SENDWININICHANGE);
 }