【问题标题】:Getting the current user's wallpaper in VB.NET在 VB.NET 中获取当前用户的壁纸
【发布时间】:2011-06-18 19:39:59
【问题描述】:

我正在用 VB.NET 编写一个程序,该程序需要获取当前用户壁纸的路径。有谁知道可以做到这一点的方法吗?

【问题讨论】:

标签: vb.net


【解决方案1】:

我知道已经很晚了,但是对于其他人...如果桌面背景(壁纸)是图片(不是纯色),您可以在目录中找到当前图片:

“C:\Users\ {用户名}\AppData\Roaming\Microsoft\Windows\Themes\”

【讨论】:

    【解决方案2】:

    您可以从注册表中读取当前壁纸。无需任何 API 调用。 这是执行此操作的代码

    Private Function GetCurrentWallpaper() As String
        ' The current wallpaper path is stored in the registry at HKCU\Control Panel\Desktop\WallPaper
        Dim rkWallPaper As RegistryKey = Registry.CurrentUser.OpenSubKey("Control Panel\Desktop", False)
        Dim WallpaperPath As String = rkWallPaper.GetValue("WallPaper").ToString()
        rkWallPaper.Close()
        ' Return the current wallpaper path
        Return WallpaperPath
    End Function
    

    【讨论】:

    • 这将不起作用,如果用户在设置后删除了壁纸
    • @automaticSoldier:是的,你是对的。这是开发人员需要解决的边缘情况。我在这里提供的是一个在大多数情况下都有效的解决方案,除非用户一直在做一些不寻常的
    【解决方案3】:

    您必须使用 SPI_GETDESKWALLPAPER 调用 SystemParametersInfo()。这将返回壁纸位图文件的路径。访问 pinvoke.net 以获取所需的声明。

    【讨论】:

    • 哇,我知道 C++ 中的那个函数,但不知道你可以在 VB.NET 中使用它!虽然实现起来真的很复杂
    • 是的,Visual Basic 团队成员不再参与证人保护计划。
    猜你喜欢
    • 2012-04-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-12-14
    相关资源
    最近更新 更多