// Use this for initialization void Start() { if (MenuController.menuController.userSettings.isDXVA == true && MenuController.menuController.userSettings.vidPath != null) { Application.targetFrameRate = 60; } else { Application.targetFrameRate = MenuController.menuController.userSettings.fps; } if (Application.isEditor == true) //disable on Unity Editor. { return; } //{UNUSED} Hide application icon from taskbar(background process). #region borderless /* * // Find the application's Window * var handle = FindWindowByCaption(IntPtr.Zero, Application.productName); * if (handle == IntPtr.Zero) return; * * // Move the Window Off Screen * SetWindowPos(handle, 1, 0, 0, 640, 360, 0); * //SetWindowPos(handle, 0, -720, 0, 720, 480, 0); //ORIGINAL * * // Remove the Window from the Taskbar * ShowWindow(handle, (uint)0); * SetWindowLong(handle, GWL_EXSTYLE, GetWindowLong(handle, GWL_EXSTYLE) | WS_EX_TOOLWINDOW); * ShowWindow(handle, (uint)5); */ #endregion // Renders behind desktop icons & windows. #region behind_icon // Find Progman windowhandle progman = StaticPinvoke.FindWindow("Progman", null); // Desktop folderView = StaticPinvoke.FindWindowEx(progman, IntPtr.Zero, "SHELLDLL_DefView", null); if (folderView == IntPtr.Zero) { do { workerWOrig = StaticPinvoke.FindWindowEx(StaticPinvoke.GetDesktopWindow(), workerWOrig, "WorkerW", null); folderView = StaticPinvoke.FindWindowEx(workerWOrig, IntPtr.Zero, "SHELLDLL_DefView", null); } while (folderView == IntPtr.Zero && workerWOrig != IntPtr.Zero); } folderView = StaticPinvoke.FindWindowEx(folderView, IntPtr.Zero, "SysListView32", "FolderView"); result = IntPtr.Zero; //todo: Set Animate controls & elements inside windows settings using Systemparametersinfo() // Send 0x052C to Progman. Spawns WorkerW behind desktop icons. // "Animate controls and elements inside windows" needs to be enabled in: This PC -> Properties -> Advanced System Settings -> Performance -> Settings. // This is used to show Fade effect on windows wallpaper change. // In windows 7 this setting is probably(?) under multiple settings. StaticPinvoke.SendMessageTimeout(progman, 0x052C, new IntPtr(0), IntPtr.Zero, StaticPinvoke.SendMessageTimeoutFlags.SMTO_NORMAL, 1000, out result); workerw = IntPtr.Zero; // Find newly created worker StaticPinvoke.EnumWindows(new StaticPinvoke.EnumWindowsProc((tophandle, topparamhandle) => { p = StaticPinvoke.FindWindowEx(tophandle, IntPtr.Zero, "SHELLDLL_DefView", IntPtr.Zero); if (p != IntPtr.Zero) { // Gets the WorkerW Window after the current one. workerw = StaticPinvoke.FindWindowEx(IntPtr.Zero, tophandle, "WorkerW", IntPtr.Zero); } return(true); }), IntPtr.Zero); if (IntPtr.Equals(workerw, IntPtr.Zero) || workerw == null) { //todo: set the settings through code using SystemParametersInfo() - complication: microsoft uses registry to update the radio button UI in the Performance dialog, //which DOES not reflect actual applied settings! o_O..will have to edit registry too. if (MenuController.menuController.WarningMsg("It looks like some settings need to be set to make rePaper work:- \n" + "1. Open This PC(My Computer)\n" + "2. Right-click empty area\n" + "3. Select Properties\n" + "4. Select Advanced System Settings\n" + "5. Under Performance tab select Settings\n" + "6. Enable Animate controls and elements inside windows & Apply.\n" + "If Windows 7 just set - Adjust for best appearance & Apply\n" + "If still not working, close & start rePaper again or restart windows." + "Press OK to Exit, Cancel to proceed anyway.", "Hold on..") == 1) { main.instance.Close_Action(null, null); } } IntPtr handle = IntPtr.Zero; // Find the application's Window, should work in 90% case handle = StaticPinvoke.FindWindowByCaption(IntPtr.Zero, Application.productName); while (handle != null && !IntPtr.Equals(handle, IntPtr.Zero)) { #region processid //Process.GetCurrentProcess().MainWindowHandle returns 0, searching with found handle instead. StaticPinvoke.GetWindowThreadProcessId(handle, out processID); unity_process = Process.GetProcessById(processID); // Verify weather the window handle is rePaper-Unity.exe before proceeding further!. if (unity_process.ProcessName.Equals(Application.productName, StringComparison.InvariantCultureIgnoreCase)) { old_unity_handle = handle; break; } else // something else!!...probably explorer window with window title caption. { Debug.Log("Different window handle found instead of rePaper-Unity, searching again!"); old_unity_handle = handle; //searching the next window handle... handle = StaticPinvoke.FindWindowEx(IntPtr.Zero, old_unity_handle, null, Application.productName); } #endregion processid } if (handle == null || IntPtr.Equals(handle, IntPtr.Zero)) { Debug.Log("Could't find unity window! Handle:- "); return; } if (MenuController.menuController.isMultiMonitor == false) { StaticPinvoke.SetWindowPos(handle, 1, 0, 0, UnityEngine.Screen.currentResolution.width, UnityEngine.Screen.currentResolution.height, 0); } else //multiple monitors detected. { /* * //Attempted to make window appear on primary monitor, failure!. * var monitor = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea; * StaticPinvoke.SetWindowPos(handle, 1, monitor.Left, monitor.Top, monitor.Width,monitor.Height, 0); */ //Success, basically offset value of desktop handle needs to be added to x,y //todo:- update pause/sleep algorithm for multiple displays. ( currently based on primary display) MoveToDisplay(MenuController.menuController.userSettings.ivar2); } //os = SystemInfo.operatingSystem.ToLowerInvariant(); //unity operating system info. if (System.Environment.OSVersion.Version.Major == 6 && System.Environment.OSVersion.Version.Minor == 1) //windows 7(min: support) { if (debuggin == false) { workerWOrig = progman; StaticPinvoke.ShowWindow(workerw, (uint)0); StaticPinvoke.SetParent(handle, progman); } } else //assuming above win7, will fail in vista etc { if (debuggin == false) { StaticPinvoke.SetParent(handle, workerw); } } #endregion behind_icon #region pause_unpause_monitor t_watcher = new Thread(new ThreadStart(Update_T)); t_watcher.IsBackground = true; //exit with application StartCoroutine(Startup()); desktopHandle = StaticPinvoke.GetDesktopWindow(); shellHandle = StaticPinvoke.GetShellWindow(); hWnd = workerWOrig; // bug fix: early launch, might detect application as hWndID. #endregion pause_unpause_monitor }