public static void Main(string[] args) { CreateHostBuilder(args) .Build() .RunAsync(); //winform设置 Application.SetHighDpiMode(HighDpiMode.SystemAware); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); //异常捕获 Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException); Application.ThreadException += Application_ThreadException; AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; //dpi 相关 //上面已经操作了不用设了 //User32WrapperEx.SetThreadAwarenessContext(DPI_AWARENESS_CONTEXT.DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE); WallpaperHelper.DoSomeMagic(); //用node+electron+http api渲染,待c#有更好的库时,再考虑c#渲染 RenderFactory.Renders.Add(typeof(ElectronWebRender), ElectronWebRender.StaticSupportTypes); //winform 处理消息循环 Application.Run(new Form() { ShowInTaskbar = false, Opacity = 0 });
public async Task ShowWallpaper(WallpaperModel wallpaper, params uint[] screenIndexs) { if (_renderProcess == null || _renderProcess.HasExited) { var renderAPIPort = NetworkHelper.GetAvailablePort(8080); _api = new WebRenderAPI("http://*****:*****@"WebRender\livewallpaperwebrender.exe"); _renderProcess = Process.Start(path, $"--hostPort={renderAPIPort}"); } HostInfo info = await _api.GetInfo(); while (info == null || !info.Initlized) { await Task.Delay(1000); info = await _api.GetInfo(); } var hosts = await _api.ShowWallpaper(wallpaper, screenIndexs); foreach (var scIndex in screenIndexs) { IntPtr windowHandle = hosts[scIndex]; WallpaperHelper.GetInstance(scIndex).SendToBackground(windowHandle); } }
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 DoWork(object state) { var count = Interlocked.Increment(ref _executionCount); _logger.LogInformation( "Timed Hosted Service is working. Count: {Count}", count); try { var unsplashApi = new UnsplashApiClient(_config); var wallpaperCom = (IDesktopWallpaper)(new DesktopWallpaperClass()); for (uint i = 0; i < wallpaperCom.GetMonitorDevicePathCount(); i++) { var monitorId = wallpaperCom.GetMonitorDevicePathAt(i); if (string.IsNullOrEmpty(monitorId)) { continue; } var photo = unsplashApi.GetRandomDesktopBackground().GetAwaiter().GetResult(); var outputPath = _config["outputPath"]; var imagePath = string.IsNullOrEmpty(outputPath) ? Path.Combine(Path.GetTempPath(), "wallpaper.jpg") : Path.Combine(outputPath, $"{DateTime.Now:yyyyMMddHHmm}_{photo.Id}.jpg"); WallpaperHelper.SetWallpaper(wallpaperCom, monitorId, imagePath, new Uri(photo.Urls.Full)); unsplashApi.CallDownloadTrackingEndpoint(photo); } } catch (Exception e) { _logger.LogError(e.Message); } }
public async static Task Main(string[] args) { var accessKey = LoadAccessKey(); var unsplashApi = new UnsplashApiClient(accessKey); var photo = await unsplashApi.GetRandomDesktopBackground(); WallpaperHelper.SetWallpaper(new Uri(photo.Urls.Full)); unsplashApi.CallDownloadTrackingEndpoint(photo); }
private void SetVirtualBackgroundImage() { //get the right virtual screen object, and draw a image for it var mon = _monitors.First(x => x.DeviceName == VirtualScreenName); using Image virtualScreenBitmap = new Bitmap(mon.Width, mon.Height); using var virtualScreenGraphic = Graphics.FromImage(virtualScreenBitmap); mon.DrawToGraphics(virtualScreenGraphic); //save the image to hd and set it virtualScreenBitmap.Save(_wallpaperSetterSettings.VirtualWallpaperFilePath, ImageFormat.Jpeg); WallpaperHelper.SetWallpaper(_wallpaperSetterSettings.VirtualWallpaperFilePath, WindowsWallpaperStyle.Tile); }
public Task ShowWallpaper(WallpaperModel wallpaper, params uint[] screenIndexs) { foreach (var index in screenIndexs) { var process = Process.Start(wallpaper.Path); // 刚创建的进程可能无法获取到MainWindowHandle属性,所以延时两秒保证属性获取正常 Thread.Sleep(2 * 1000); WallpaperHelper.GetInstance(index).SendToBackground(process.MainWindowHandle); // 设置要接受鼠标消息的窗口的句柄 mouseEventReciver.HTargetWindow = process.MainWindowHandle; } return(Task.CompletedTask); }
internal void ShowWallpaper(Control control) { IntPtr windowHandle = IntPtr.Zero; this.InvokeIfRequired(() => { Controls.Clear(); control.Dock = DockStyle.Fill; Controls.Add(control); Opacity = 1; Refresh(); windowHandle = Handle; }); WallpaperHelper.GetInstance(_screenIndex).SendToBackground(windowHandle); }
public async Task ShowWallpaper(WallpaperModel wallpaper, params int[] screenIndexs) { if (_renderProcess == null || _renderProcess.HasExited) { var renderAPIPort = GetAvailablePort(9000); _renderProcess = Process.Start("", renderAPIPort.ToString()); } foreach (var scIndex in screenIndexs) { IntPtr windowHandle = await GetHostFromRemote(scIndex); WallpaperHelper.GetInstance(scIndex).SendToBackground(windowHandle); } throw new System.NotImplementedException(); }
internal void ShowWallpaper(Control control) { Load += RenderHost_Load; Show(); Application.DoEvents(); Controls.Clear(); control.Dock = DockStyle.Fill; Controls.Add(control); Update(); //Invalidate(); //await Task.Delay(200); Opacity = 1; Refresh(); WallpaperHelper.GetInstance(_screenIndex).SendToBackground(Handle); }
private void SetCombinedBackgroundImage() { //get the right true screen objects, and draw a image for it var mons = _monitors.Where(x => x.DeviceName != VirtualScreenName && x.DeviceName != LockScreenName); using Image virtualScreenBitmap = new Bitmap(SystemInformation.VirtualScreen.Width, SystemInformation.VirtualScreen.Height); using var virtualScreenGraphic = Graphics.FromImage(virtualScreenBitmap); foreach (var mon in mons) { mon.DrawToGraphics(virtualScreenGraphic); } //save the image to hd and set it virtualScreenBitmap.Save(_wallpaperSetterSettings.CombinedWallpaperFilePath, ImageFormat.Jpeg); WallpaperHelper.SetWallpaper(_wallpaperSetterSettings.CombinedWallpaperFilePath, WindowsWallpaperStyle.Tile); }
internal void ShowWallpaper(Control renderControl) { IntPtr windowHandle = IntPtr.Zero; WallpaperManager.UIInvoke(() => { try { Controls.Clear(); renderControl.Dock = DockStyle.Fill; Controls.Add(renderControl); Opacity = 1; Refresh(); windowHandle = Handle; } catch (Exception ex) { } }); WallpaperHelper.GetInstance(_screenIndex).SendToBackground(windowHandle); }
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) { } }
public void SetWallpaper() { if (Debugger.IsAttached) { //WallpaperHelper.SetWallpaper(WideImage, WindowsWallpaperStyle.Fit); //WallpaperHelper.SetWallpaper(WideImage, WindowsWallpaperStyle.Fill); //WallpaperHelper.SetWallpaper(WideImage, WindowsWallpaperStyle.Center); //WallpaperHelper.SetWallpaper(WideImage, WindowsWallpaperStyle.Span); //WallpaperHelper.SetWallpaper(WideImage, WindowsWallpaperStyle.Stretch); WallpaperHelper.SetWallpaper(WideImage, WindowsWallpaperStyle.Tile); //WallpaperHelper.SetWallpaper(HighImage, WindowsWallpaperStyle.Fit); //WallpaperHelper.SetWallpaper(HighImage, WindowsWallpaperStyle.Fill); //WallpaperHelper.SetWallpaper(HighImage, WindowsWallpaperStyle.Center); //WallpaperHelper.SetWallpaper(HighImage, WindowsWallpaperStyle.Span); //WallpaperHelper.SetWallpaper(HighImage, WindowsWallpaperStyle.Stretch); //WallpaperHelper.SetWallpaper(HighImage, WindowsWallpaperStyle.Tile); } else { Assert.Pass(); } }
//one for each screen --> direct to Windows API /// <summary> /// Sets given Wallpaper foreach Screen /// </summary> /// <param name="file">Wallpaper to set</param> public void SetSameWallOnEveryScreen(string file) { var attr = _wallpaperSetterSettings.WallpaperMode.GetAttribute <WallpaperModeWindowsMappingAttribute>(); WallpaperHelper.SetWallpaper(file, attr.WindowsWallpaperStyle); }
public async void CloseWallpaper(params uint[] screenIndexs) { await _api.CloseWallpaper(screenIndexs); WallpaperHelper.RefreshWallpaper(); }
public static void Initlize() { //dpi 相关 User32WrapperEx.SetThreadAwarenessContext(DPI_AWARENESS_CONTEXT.DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE); WallpaperHelper.DoSomeMagic(); }
/// <summary> /// Sets the current desktop wallpaper to the specified image. /// </summary> /// <param name="imagePath">The path of the image to set as the wallpaper.</param> public void SetWallpaper(string imagePath) { if (_settingWallpaper) { return; } if (!File.Exists(imagePath)) { return; } _settingWallpaper = true; try { // get name cached var cachedImageName = GetCachedImageName(imagePath); // generate cached image if one doesn't exist if (!File.Exists(cachedImageName)) { var desktopSize = DesktopHelper.GetPrimaryDesktopSize(); var image = Image.FromFile(imagePath); ExifRotate(image); Image wallpaper; if (LandscapeOnly) { if (image.Width < image.Height) { _settingWallpaper = false; ChangeWallpaper(); return; } } var cropWallpaper = false; if (desktopSize.Width > desktopSize.Height && image.Width > image.Height) { cropWallpaper = true; } else if (desktopSize.Width < desktopSize.Height && image.Width < image.Height) { cropWallpaper = true; } if (cropWallpaper) { wallpaper = ImageHelper.ScaleAndCropImageToFit(image, desktopSize); } else { var smallDesktopSize = new Size(desktopSize.Width / 4, desktopSize.Height / 4); var scaledBackgroundImage = ImageHelper.ScaleAndCropImageToFit(image, smallDesktopSize); var darkBackgroundImage = ImageHelper.DarkenImage(scaledBackgroundImage, 0.5); var blurredBackgroundImage = ImageHelper.BlurFilter(darkBackgroundImage, 10); wallpaper = ImageHelper.ScaleAndCropImageToFit(blurredBackgroundImage, desktopSize); var scaledImage = ImageHelper.ScaleImageToFit(image, desktopSize); using (var graphics = Graphics.FromImage(wallpaper)) { var x = (desktopSize.Width - scaledImage.Width) / 2; var y = (desktopSize.Height - scaledImage.Height) / 2; var imageLocation = new Point(x, y); graphics.DrawImage(scaledImage, imageLocation); } scaledImage.Dispose(); scaledBackgroundImage.Dispose(); blurredBackgroundImage.Dispose(); darkBackgroundImage.Dispose(); } if (ApplyMedianFilter) { using (var medianImage = ImageHelper.MedianFilter(wallpaper, 4)) { medianImage.Save(cachedImageName, ImageFormat.Jpeg); } } else { wallpaper.Save(cachedImageName, ImageFormat.Jpeg); } wallpaper.Dispose(); image.Dispose(); } // get name for wallpaper bitmap in temp folder var wallpaperPath = Path.Combine(Path.GetTempPath(), "Wallpaper.bmp"); // save cached image as wallpaper file and set as current wallpaper using (var image = Image.FromFile(cachedImageName)) { image.Save(wallpaperPath, ImageFormat.Bmp); } WallpaperHelper.SetWallpaper(wallpaperPath); // set as recent wallpaper CurrentWallpaperImage = imagePath; AddToRecentWallpaperList(imagePath); } catch (Exception e) { var message = $"Error setting wallpaper'{imagePath}'\r\n{e}"; AddLogEntry(message); SaveLog(); } finally { _settingWallpaper = false; } }
static WallpaperApi() { //怀疑某些系统用不了 WallpaperHelper.DoSomeMagic(); }
private LiveWallpaper() { //dpi 相关 User32WrapperEx.SetThreadAwarenessContext(DPI_AWARENESS_CONTEXT.DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE); WallpaperHelper.DoSomeMagic(); }