我正在研究一种需要获取当前用户壁纸路径的工具.
在Windows 7上,我可以通过阅读获得
HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Desktop\General\WallpaperSource.
在我的Windows 8安装中,该密钥始终具有该值
C:\Users\Peter\AppData\Roaming\Microsoft\Windows Photo Viewer\Windows Photo Viewer Wallpaper.jpg
这甚至不是当前设置的壁纸.
还有其他可以依赖的钥匙吗?
Rei*_*man 11
您最好使用SPI_SETDESKWALLPAPER选项调用SystemParametersInfo来设置桌面墙纸.据我所知,您正在使用的注册表项未记录,因此可以随时更改而不会发出警告.
有关如何使用SPI_SETDESKWALLPAPER调用SystemParametersInfo的示例,请参阅此堆栈溢出问题.
Rob*_*Rob 10
很大程度上基于pinvoke.net上提供的代码,检索当前用户桌面壁纸的正确方法是使用该SystemParametersInfo功能.这样做的示例如下:
using System;
using System.Runtime.InteropServices;
namespace WallpaperPathRetrieval
{
class Program
{
[DllImport("user32.dll", CharSet = CharSet.Auto)]
private static extern Int32 SystemParametersInfo(UInt32 action,
UInt32 uParam, string vParam, UInt32 winIni);
private static readonly UInt32 SPI_GETDESKWALLPAPER = 0x73;
private static uint MAX_PATH = 260;
static void Main(string[] args)
{
string wallpaper = new string('\0', (int)MAX_PATH);
SystemParametersInfo(SPI_GETDESKWALLPAPER, MAX_PATH, wallpaper, 0);
wallpaper = wallpaper.Substring(0, wallpaper.IndexOf('\0'));
}
}
}
Run Code Online (Sandbox Code Playgroud)
你提到的关键不正确.听我说你已经从Internet Explorer放置了一个图像作为桌面背景,并且打开了该密钥以进行注册.
获取桌面背景位置的正确键是: 确认:XP,CE,Vista,7,8
HKEY_CURRENT_USER\Control Panel\Desktop\Wallpaper
Run Code Online (Sandbox Code Playgroud)
细节:
此外,HKEY_CURRENT_USER\Control Panel\Desktop\您将找到其他壁纸相关选项以应用不同的样式:中心,平铺和拉伸.
HKEY_CURRENT_USER\Control Panel\Desktop\WallpaperStyle
HKEY_CURRENT_USER\Control Panel\Desktop\TileWallpaper
Run Code Online (Sandbox Code Playgroud)
要应用样式,请使用以下指南:
中央
WallpaperStyle = 0
TileWallpaper = 0
Run Code Online (Sandbox Code Playgroud)瓦
WallpaperStyle = 0
TileWallpaper = 1
Run Code Online (Sandbox Code Playgroud)伸展
WallpaperStyle = 2
TileWallpaper = 0
Run Code Online (Sandbox Code Playgroud)| 归档时间: |
|
| 查看次数: |
23119 次 |
| 最近记录: |