c#获取windows桌面背景 c#获取windows桌面背景代码示例

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

c#获取windows桌面背景 c#获取windows桌面背景代码示例

  2021-03-19 我要评论
想了解c#获取windows桌面背景代码示例的相关内容吗,在本文为您仔细讲解c#获取windows桌面背景的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:c#,windows桌面,下面大家一起来学习吧。

复制代码 代码如下:

#region 获取windows桌面背景
        [System.Runtime.InteropServices.DllImport("user32.dll", CharSet = System.Runtime.InteropServices.CharSet.Auto, SetLastError = true)]
        public static extern int SystemParametersInfo(int uAction, int uParam, StringBuilder lpvParam, int fuWinIni);

        private const int SPI_GETDESKWALLPAPER = 0x0073;
        #endregion


void WindowsBtn_Click(object sender, RoutedEventArgs e)
        {
            //定义存储缓冲区大小
            StringBuilder s = new StringBuilder(300);
            //获取Window 桌面背景图片地址,使用缓冲区
            SystemParametersInfo(SPI_GETDESKWALLPAPER, 300, s, 0);
            //缓冲区中字符进行转换
            string wallpaper_path = s.ToString(); //系统桌面背景图片路径
         }

调用windows api获取

使用的时候需要注意StringBuilder的大小不能小于255,因为windows的路径最大支持255,如果定义过小...

如果当前系统桌面无背景或为纯色则返回空.

猜您喜欢

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们