📄 dwallpaper.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Runtime.InteropServices ;
using System.IO ;
using System.Diagnostics;
namespace XP界面优化精灵
{
/// <summary>
/// DWallpaper 的摘要说明。
/// </summary>
public class DWallpaper : System.Windows.Forms.Form
{
[DllImport("user32.dll", EntryPoint="FindWindow")] public static extern int FindWindow ( string lpClassName, string lpWindowName );
[DllImport("user32.dll", EntryPoint="ShowWindow")] public static extern int ShowWindow ( int hwnd, int nCmdShow );
private System.Windows.Forms.TabControl tabControl1;
private System.Windows.Forms.TabPage tabPage1;
private System.Windows.Forms.CheckBox cb_HideDesktopIcon;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.ListBox lb_picList;
private System.Windows.Forms.Button bn_AddImage;
private System.Windows.Forms.Button bn_DelImage;
private System.Windows.Forms.TrackBar trackBar;
private System.Windows.Forms.Button bn_Apply;
private System.Windows.Forms.ComboBox cb_1;
private System.Windows.Forms.Label lb_showTimer;
private System.Windows.Forms.Timer changePic;
private System.Windows.Forms.Button bn_AppWallPaper;
private System.ComponentModel.IContainer components;
public DWallpaper()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(DWallpaper));
this.tabControl1 = new System.Windows.Forms.TabControl();
this.tabPage1 = new System.Windows.Forms.TabPage();
this.bn_Apply = new System.Windows.Forms.Button();
this.bn_DelImage = new System.Windows.Forms.Button();
this.bn_AddImage = new System.Windows.Forms.Button();
this.lb_showTimer = new System.Windows.Forms.Label();
this.cb_1 = new System.Windows.Forms.ComboBox();
this.label2 = new System.Windows.Forms.Label();
this.trackBar = new System.Windows.Forms.TrackBar();
this.lb_picList = new System.Windows.Forms.ListBox();
this.cb_HideDesktopIcon = new System.Windows.Forms.CheckBox();
this.label1 = new System.Windows.Forms.Label();
this.changePic = new System.Windows.Forms.Timer(this.components);
this.bn_AppWallPaper = new System.Windows.Forms.Button();
this.tabControl1.SuspendLayout();
this.tabPage1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.trackBar)).BeginInit();
this.SuspendLayout();
//
// tabControl1
//
this.tabControl1.Controls.Add(this.tabPage1);
this.tabControl1.Location = new System.Drawing.Point(8, 4);
this.tabControl1.Name = "tabControl1";
this.tabControl1.SelectedIndex = 0;
this.tabControl1.Size = new System.Drawing.Size(456, 312);
this.tabControl1.TabIndex = 6;
//
// tabPage1
//
this.tabPage1.BackColor = System.Drawing.Color.White;
this.tabPage1.Controls.Add(this.bn_AppWallPaper);
this.tabPage1.Controls.Add(this.bn_Apply);
this.tabPage1.Controls.Add(this.bn_DelImage);
this.tabPage1.Controls.Add(this.bn_AddImage);
this.tabPage1.Controls.Add(this.lb_showTimer);
this.tabPage1.Controls.Add(this.cb_1);
this.tabPage1.Controls.Add(this.label2);
this.tabPage1.Controls.Add(this.trackBar);
this.tabPage1.Controls.Add(this.lb_picList);
this.tabPage1.Controls.Add(this.cb_HideDesktopIcon);
this.tabPage1.Controls.Add(this.label1);
this.tabPage1.Location = new System.Drawing.Point(4, 21);
this.tabPage1.Name = "tabPage1";
this.tabPage1.Size = new System.Drawing.Size(448, 287);
this.tabPage1.TabIndex = 0;
this.tabPage1.Text = "动态墙纸";
//
// bn_Apply
//
this.bn_Apply.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.bn_Apply.Location = new System.Drawing.Point(348, 238);
this.bn_Apply.Name = "bn_Apply";
this.bn_Apply.Size = new System.Drawing.Size(84, 23);
this.bn_Apply.TabIndex = 21;
this.bn_Apply.Text = "实现动态墙纸";
this.bn_Apply.Click += new System.EventHandler(this.bn_Apply_Click);
//
// bn_DelImage
//
this.bn_DelImage.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.bn_DelImage.Location = new System.Drawing.Point(348, 208);
this.bn_DelImage.Name = "bn_DelImage";
this.bn_DelImage.Size = new System.Drawing.Size(84, 23);
this.bn_DelImage.TabIndex = 19;
this.bn_DelImage.Text = "删除图片";
this.bn_DelImage.Click += new System.EventHandler(this.bn_DelImage_Click);
//
// bn_AddImage
//
this.bn_AddImage.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.bn_AddImage.Location = new System.Drawing.Point(348, 178);
this.bn_AddImage.Name = "bn_AddImage";
this.bn_AddImage.Size = new System.Drawing.Size(84, 23);
this.bn_AddImage.TabIndex = 18;
this.bn_AddImage.Text = "添加图片";
this.bn_AddImage.Click += new System.EventHandler(this.bn_AddImage_Click);
//
// lb_showTimer
//
this.lb_showTimer.AutoSize = true;
this.lb_showTimer.Location = new System.Drawing.Point(256, 164);
this.lb_showTimer.Name = "lb_showTimer";
this.lb_showTimer.Size = new System.Drawing.Size(72, 17);
this.lb_showTimer.TabIndex = 25;
this.lb_showTimer.Text = "1秒更换一次";
//
// cb_1
//
this.cb_1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.cb_1.Items.AddRange(new object[] {
"居中",
"平铺",
"拉伸"});
this.cb_1.Location = new System.Drawing.Point(138, 198);
this.cb_1.Name = "cb_1";
this.cb_1.Size = new System.Drawing.Size(121, 20);
this.cb_1.TabIndex = 24;
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(20, 202);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(85, 17);
this.label2.TabIndex = 23;
this.label2.Text = "图片显示方式:";
//
// trackBar
//
this.trackBar.AutoSize = false;
this.trackBar.LargeChange = 500;
this.trackBar.Location = new System.Drawing.Point(138, 154);
this.trackBar.Maximum = 5000;
this.trackBar.Minimum = 500;
this.trackBar.Name = "trackBar";
this.trackBar.Size = new System.Drawing.Size(116, 28);
this.trackBar.SmallChange = 100;
this.trackBar.TabIndex = 20;
this.trackBar.TickFrequency = 500;
this.trackBar.Value = 1000;
this.trackBar.Scroll += new System.EventHandler(this.trackBar_Scroll);
//
// lb_picList
//
this.lb_picList.ItemHeight = 12;
this.lb_picList.Location = new System.Drawing.Point(16, 20);
this.lb_picList.Name = "lb_picList";
this.lb_picList.Size = new System.Drawing.Size(418, 124);
this.lb_picList.TabIndex = 17;
//
// cb_HideDesktopIcon
//
this.cb_HideDesktopIcon.Location = new System.Drawing.Point(22, 240);
this.cb_HideDesktopIcon.Name = "cb_HideDesktopIcon";
this.cb_HideDesktopIcon.TabIndex = 16;
this.cb_HideDesktopIcon.Text = "隐藏桌面图标";
this.cb_HideDesktopIcon.CheckedChanged += new System.EventHandler(this.cb_HideDesktopIcon_CheckedChanged);
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(20, 160);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(122, 17);
this.label1.TabIndex = 22;
this.label1.Text = "更换图片的时间间隔:";
//
// changePic
//
this.changePic.Interval = 1000;
this.changePic.Tick += new System.EventHandler(this.changePic_Tick);
//
// bn_AppWallPaper
//
this.bn_AppWallPaper.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.bn_AppWallPaper.Location = new System.Drawing.Point(348, 150);
this.bn_AppWallPaper.Name = "bn_AppWallPaper";
this.bn_AppWallPaper.Size = new System.Drawing.Size(84, 23);
this.bn_AppWallPaper.TabIndex = 26;
this.bn_AppWallPaper.Text = "设为当前墙纸";
this.bn_AppWallPaper.Click += new System.EventHandler(this.bn_AppWallPaper_Click);
//
// DWallpaper
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(468, 322);
this.Controls.Add(this.tabControl1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.HelpButton = true;
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "DWallpaper";
this.ShowInTaskbar = false;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "动态墙纸";
this.Closing += new System.ComponentModel.CancelEventHandler(this.DWallpaper_Closing);
this.Load += new System.EventHandler(this.DWallpaper_Load);
this.tabControl1.ResumeLayout(false);
this.tabPage1.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.trackBar)).EndInit();
this.ResumeLayout(false);
}
#endregion
private void DWallpaper_Load(object sender, System.EventArgs e)
{
this.TopMost=action.isTopMost;
LoadPicList();
}
private void cb_HideDesktopIcon_CheckedChanged(object sender, System.EventArgs e)
{
if(this.cb_HideDesktopIcon.Checked )
{
int hDesktop = FindWindow("ProgMan", null);
ShowWindow(hDesktop, 0);
}
else
{
int hDesktop = FindWindow("ProgMan", null);
ShowWindow(hDesktop, 5);
}
}
private void LoadPicList()
{
this.lb_picList.Items.Clear ();
string [] file =Directory.GetFiles (Application.StartupPath +"\\Wallpaper\\pic");
foreach(string f in file)
{
string subf=f.Substring (f.LastIndexOf ("\\")+1);
this.lb_picList.Items.Add ((object)f);
}
}
private void bn_AddImage_Click(object sender, System.EventArgs e)
{
try
{
OpenFileDialog ofd=new OpenFileDialog ();
ofd.Filter ="*.bmp | *.bmp | *.jpg | *.jpg | *.gif | *.gif";
if(ofd.ShowDialog ()==DialogResult.OK )
{
string filename=ofd.FileName.Substring (ofd.FileName.LastIndexOf("\\")+1);
if(File.Exists (Application.StartupPath+"\\Wallpaper\\pic\\"+filename))
{
DialogResult dr=MessageBox.Show ("文件己存在,是否替换该文件",action.Caption,System.Windows.Forms.MessageBoxButtons.YesNoCancel);
if(dr==DialogResult.Yes)
{
File.Copy (ofd.FileName ,Application.StartupPath+"\\Wallpaper\\pic\\"+filename,true);
}
else if (dr==DialogResult.No )
{
SaveFileDialog sfd=new SaveFileDialog ();
sfd.Filter ="*.bmp | *.bmp";
sfd.InitialDirectory=Application.StartupPath+"\\Wallpaper\\pic\\";
if(sfd.ShowDialog ()==DialogResult.OK )
{
File.Copy (ofd.FileName ,sfd.FileName);
}
}
}
else
{
File.Copy (ofd.FileName ,Application.StartupPath+"\\Wallpaper\\pic\\"+filename,true);
}
DWallpaper_Load(sender,e);
}
}
catch
{
}
}
private void bn_DelImage_Click(object sender, System.EventArgs e)
{
if(this.lb_picList.SelectedItems.Count >0)
{
File.Delete (this.lb_picList.SelectedItem.ToString ());
DWallpaper_Load(sender,e);
}
}
private void bn_Apply_Click(object sender, System.EventArgs e)
{
this.changePic .Interval =this.trackBar.Value ;
this.changePic.Enabled =!this.changePic.Enabled ;
if(this.changePic.Enabled)
{
isRunTime (true);
}
else
{
isRunTime(false);
}
}
private void trackBar_Scroll(object sender, System.EventArgs e)
{
this.lb_showTimer.Text =""+this.trackBar.Value /1000.0+"秒更换一次";
}
int n=0;
private void changePic_Tick(object sender, System.EventArgs e)
{
try
{
Wallpaper.ADesktopClass wa=new Wallpaper.ADesktopClass ();
wa.ChangeWallpaper (this.lb_picList.Items [n].ToString (),short.Parse (this.cb_1.SelectedIndex.ToString()),false);
n++;
if(n>=this.lb_picList.Items.Count)
{
n=0;
}
}
catch
{
Process.Start ("regsvr32.exe","\""+Application.StartupPath +"\\data\\Wallpaper.dll\"");
}
}
private void isRunTime(bool isrun)
{
if(isrun)
{
this.bn_Apply.Text ="关闭动态墙纸";
this.bn_AddImage .Enabled =false;
this.bn_DelImage .Enabled =false;
this.trackBar.Enabled =false;
}
else
{
this.bn_Apply.Text ="实现动态墙纸";
this.bn_AddImage .Enabled =true;
this.bn_DelImage .Enabled =true;
this.trackBar.Enabled =true;
}
}
private void DWallpaper_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
e.Cancel =true;
this.Hide ();
}
private void bn_AppWallPaper_Click(object sender, System.EventArgs e)
{
if(this.lb_picList.SelectedItem!=null)
{
Wallpaper.ADesktopClass wa=new Wallpaper.ADesktopClass ();
wa.ChangeWallpaper(this.lb_picList.SelectedItems[0].ToString(),1,true);
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -