如何将桌面窗口替换为应用程序窗口 [英] How to replace the desktop window to the application window
本文介绍了如何将桌面窗口替换为应用程序窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好。
如何将桌面窗口替换为应用程序窗口,例如C#或C ++。我需要将桌面默认图片更改为我的统一应用程序(或gif或视频)。
我希望得到您的帮助。
Hello.
How I can replace the desktop window to the application window, with C# or C++ for example. I need to change desktop default picture to my unity application (or gif, or video).
I hope for your help.
推荐答案
您好Tewarami,
Hi Tewarami,
感谢您在此发帖。
>> 我需要将桌面默认图片更改为我的统一应用程序(或gif或视频)。
如果要更改桌面默认图片,可以尝试使用代码下面。
If you want to change the desktop default picture, you could try the code below.
using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp
{
class Change_desktop_picture
{
/// <summary>
/// set the parameter of system
/// </summary>
/// <param name="uAction"></param>
/// <param name="uParam"></param>
/// <param name="lpvParam"></param>
/// <param name="fuWinIni"></param>
/// <example></example>
/// <returns></returns>
[DllImport("user32.dll", EntryPoint = "SystemParametersInfo")]
public static extern int SystemParametersInfo(UAction uAction, int uParam, StringBuilder lpvParam, int fuWinIni);
static void Main(string[] args)
{
GetBackgroud();
SetBackgroud(@"C:\Users\Desktop\2.jpg");
}
public enum UAction
{
/// <summary>
/// set the desktop background image
/// </summary>
SPI_SETDESKWALLPAPER = 0x0014,
/// <summary>
/// set the desktop background image
/// </summary>
SPI_GETDESKWALLPAPER = 0x0073,
}
public static string GetBackgroud()
{
StringBuilder s = new StringBuilder(300);
SystemParametersInfo(UAction.SPI_GETDESKWALLPAPER, 300, s, 0);
return s.ToString();
}
/// <summary>
/// set the desktop background image
/// </summary>
/// <param name="fileName">the path of image</param>
/// <returns></returns>
public static int SetBackgroud(string fileName)
{
int result = 0;
if (File.Exists(fileName))
{
StringBuilder s = new StringBuilder(fileName);
result = SystemParametersInfo(UAction.SPI_SETDESKWALLPAPER, 0, s, 0x2);
}
return result;
}
/// <summary>
/// set the option of registry
/// </summary>
/// <param name="optionsName">the name of registry</param>
/// <param name="optionsData">set the data of registry</param>
/// <param name="msg"></param>
/// <returns></returns>
public static bool SetOptions(string optionsName, string optionsData, ref string msg)
{
bool returnBool = true;
RegistryKey classesRoot = Registry.CurrentUser;
RegistryKey registryKey = classesRoot.OpenSubKey(@"Control Panel\Desktop", true);
try
{
if (registryKey != null)
{
registryKey.SetValue(optionsName.ToUpper(), optionsData);
}
else
{
returnBool = false;
}
}
catch
{
returnBool = false;
msg = "Error when read the registry";
}
finally
{
classesRoot.Close();
registryKey.Close();
}
return returnBool;
}
}
}
最好的问候,
Wendy
这篇关于如何将桌面窗口替换为应用程序窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文