手机
当前位置:查字典教程网 >编程开发 >C#教程 >c#获取windows桌面背景代码示例
c#获取windows桌面背景代码示例
摘要:复制代码代码如下:#region获取windows桌面背景[System.Runtime.InteropServices.DllImport...

复制代码 代码如下:

#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,如果定义过小...

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

【c#获取windows桌面背景代码示例】相关文章:

C#启动windows服务方法的相关问题分析

c# 获取网页中指定的字符串信息的实例代码

c#(Socket)异步套接字代码示例

c# 冒泡排序算法(Bubble Sort) 附实例代码

c# 对windows用户和组操作实例

C#动态执行字符串(动态创建代码)的实例代码

C#编写的windows计算器的实例代码

c# 获取CookieContainer的所有cookies函数代码

winform天气预报小工具(附源码下载)

C#几种获取网页源文件代码的实例

精品推荐
分类导航