程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> C# >> 關於C# >> c#獲取當前桌面背景路徑 源代碼

c#獲取當前桌面背景路徑 源代碼

編輯:關於C#
 

C#獲取當前用戶的壁紙的路徑,,要是純色則返回空、

編譯環境:vs2013 .net 4.5

代碼如下:

c#獲取當前桌面背景路徑 源代碼
 

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace 獲取windows桌面背景
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{

}
#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

private void button1_Click(object sender, EventArgs e)
{
//定義存儲緩沖區大小
StringBuilder s = new StringBuilder(300);
//獲取Window 桌面背景圖片地址,使用緩沖區
SystemParametersInfo(SPI_GETDESKWALLPAPER, 300, s, 0);
//緩沖區中字符進行轉換
string wallpaper_path = s.ToString(); //系統桌面背景圖片路徑
textBox1.Text = wallpaper_path;
if (textBox1.Text == "")
{
button2.Visible = false;
MessageBox.Show("桌面壁紙為純色或空");
}
else
{
button2.Visible = true;
}
}

private void button2_Click(object sender, EventArgs e)
{
System.Diagnostics.Process.Start("explorer.exe", textBox1.Text);
}
}
}

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved