internal void ShowWallpaper(IntPtr wallpaperHandle) { IntPtr hostForm = IntPtr.Zero; WallpaperApi.UIInvoke(() => { try { Controls.Clear(); Opacity = 1; hostForm = Handle; } catch (Exception ex) { System.Diagnostics.Debug.WriteLine($"ShowWallpaper ex:{ex}"); } }); //hostfrom下潜桌面 WallpaperHelper.GetInstance(_screenName).SendToBackground(hostForm); //壁纸parent改为hostform User32Wrapper.SetParent(wallpaperHandle, hostForm); //把壁纸全屏铺满 hostform WallpaperHelper.FullScreen(wallpaperHandle, hostForm); }
private void LoadApplication(string path, IntPtr containerHandle) { try { Stopwatch sw = new Stopwatch(); sw.Start(); int timeout = 10 * 1000; // Timeout value (10s) in case we want to cancel the task if it's taking too long. ProcessStartInfo info = new ProcessStartInfo(path); info.WindowStyle = ProcessWindowStyle.Maximized; info.CreateNoWindow = true; Process targetProcess = Process.Start(info); while (targetProcess.MainWindowHandle == IntPtr.Zero) { System.Threading.Thread.Sleep(10); int pid = targetProcess.Id; targetProcess.Dispose(); //mainWindowHandle不会变,重新获取 targetProcess = Process.GetProcessById(pid); if (sw.ElapsedMilliseconds > timeout) { sw.Stop(); return; } } _currentTargetHandle = targetProcess.MainWindowHandle; _currentPid = targetProcess.Id; DesktopMouseEventReciver.HTargetWindows.Add(_currentTargetHandle); // 用当前窗口显示exe SetParent(_currentTargetHandle, containerHandle); WallpaperHelper.FullScreen(_currentTargetHandle, containerHandle); } catch (Exception ex) { } }