一 : 解析问题
1. Windows 7 主题在:%windir%\Resources\Themes :
2: 我们通过shell 命令 (这个是msdn中提到的)
rundll32.exe %SystemRoot%\system32\shell32.dll,Control_RunDLL %SystemRoot%\system32\desk.cpl desk,@Themes /Action:OpenTheme /file:" %SystemRoot%\Resources\Themes\architecture.theme"
3: 写代码
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- using System.IO;
- using System.Threading;
- using System.Diagnostics;
- namespace win7改变主题
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- string sPath = Environment.GetEnvironmentVariable("windir");//获取系统变量 windir(windows)
- DirectoryInfo directoryInfo = new DirectoryInfo(sPath + @"\Resources\Themes\");
- foreach (FileInfo i in directoryInfo.GetFiles("*.theme"))
- {
- comboBox1.Items.Add(i.FullName);
- }
- }
- private void button1_Click(object sender, EventArgs e)
- {
- if (comboBox1.SelectedIndex == -1)
- {
- return;
- }
- string sFile = comboBox1.SelectedItem.ToString();
- string sCmd = string.Format(@"
- rundll32.exe %SystemRoot%\system32\shell32.dll,Control_RunDLL %SystemRoot%\system32\desk.cpl desk,@Themes /Action:OpenTheme /file:""{0}""", sFile); //cmd命令
- Process cmd = new Process();
- cmd.StartInfo.FileName = "cmd";
- cmd.StartInfo.RedirectStandardInput = true;
- cmd.StartInfo.RedirectStandardOutput = true;
- cmd.StartInfo.CreateNoWindow = true;
- cmd.StartInfo.UseShellExecute = false;
- cmd.Start();
- cmd.StandardInput.WriteLine(sCmd);
- cmd.StandardInput.Flush();
- cmd.StandardInput.Close();
- cmd.Close();
- cmd.Dispose();
- }
- }
- }
二 执行程序 如图:
三 : 程序源代码 下载:
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END