📄 action.cs
字号:
using System;
using Microsoft.Win32 ;
using System.IO ;
using System.Runtime.InteropServices ;
using System.Drawing;
namespace XP界面优化精灵
{
/// <summary>
/// 此类中包括对一些对系统注册表返问以及API函数的调用的功能.
/// </summary>
public class action
{
/// <summary>
/// 对光驱的操作
/// </summary>
[DllImport("winmm.dll")]
public static extern int mciSendString(string s1,string s2,int i1,int i2);
//对话框标题
public static string Caption="XP界面优化精灵";
public static bool isTopMost=false;
#region 系统托盘上的文字
/// <summary>
/// 设置系统托盘上的文字
/// </summary>
/// <param name="toolbartext"></param>
public static void setToolBarText(string toolbartext)
{
try
{
RegistryKey rk=Registry.CurrentUser.OpenSubKey(@"Control Panel\International\",true);
rk.SetValue("sTimeFormat",toolbartext+" HH:mm:ss");
rk.Close ();
}
catch(Exception ee )
{
throw ee;
}
}
/// <summary>
/// 取消系统托盘上的文字
/// </summary>
public static void cancelToolBarText()
{
try
{
RegistryKey rk=Registry.CurrentUser.OpenSubKey(@"Control Panel\International\",true);
rk.SetValue("sTimeFormat","HH:mm:ss");
rk.Close ();
}
catch(Exception ee )
{
throw ee;
}
}
#endregion
#region WINDOWS启动时的对话框的提示文字和标题
/// <summary>
/// 设置WINDOWS启动时的对话框的提示文字和标题
/// </summary>
/// <param name="caption"></param>
/// <param name="text"></param>
public static void setboolDialog(string caption ,string text)
{
try
{
RegistryKey rk=Registry.LocalMachine.OpenSubKey (@"SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\",true);
rk.SetValue("LegalNoticeCaption",caption);
rk.SetValue("LegalNoticeText",text);
rk.Close ();
}
catch(Exception ee )
{
throw ee;
}
}
/// <summary>
/// 取消WINDOWS启动时的对话框的提示文字和标题
/// </summary>
public static void cancelboolDialog()
{
try
{
RegistryKey rk=Registry.LocalMachine.OpenSubKey (@"SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\",true);
rk.SetValue("LegalNoticeCaption","");
rk.SetValue("LegalNoticeText","");
rk.Close ();
}
catch(Exception ee )
{
throw ee;
}
}
/// <summary>
/// 得到WINDOWS启动时的对话框的提示文字和标题
/// </summary>
public static void getboolDialog(ref string caption,ref string text)
{
try
{
RegistryKey rk=Registry.LocalMachine.OpenSubKey (@"SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\",true);
caption =(string)rk.GetValue("LegalNoticeCaption");
text=(string)rk.GetValue("LegalNoticeText");
rk.Close ();
}
catch(Exception ee )
{
throw ee;
}
}
#endregion
#region 配置文件设置
/// <summary>
/// 写下选项设置
/// </summary>
/// <param name="istrue1">主窗体是否有渐隐效果</param>
/// <param name="istrue2">主窗口是否基于所有窗体之前</param>
/// <param name="Opacity">主窗体透明度</param>
/// <param name="path">写入路径</param>
public static void WriteSelectItemSet(bool istrue1,bool istrue2,int Opacity,string path)
{
try
{
StreamWriter sw=new StreamWriter (path+"\\selectItem.ini",false);
sw.WriteLine ("isOpacity="+istrue1.ToString ());
sw.WriteLine ("isTopMost="+istrue2.ToString ());
sw.WriteLine ("Opacity="+Opacity.ToString ());
sw.Close ();
}
catch(Exception ee )
{
throw ee;
}
}
/// <summary>
/// 读入选项设置
/// </summary>
/// <param name="istrue1">主窗体是否有渐隐效果</param>
/// <param name="istrue2">主窗口是否基于所有窗体之前</param>
/// <param name="Opacity">主窗体透明度</param>
/// <param name="path">读入路径</param>
public static void ReadSelectItemSet(ref bool istrue1,ref bool istrue2,ref int Opacity,string path)
{
try
{
StreamReader sr=new StreamReader (path+"\\selectItem.ini");
string temp=sr.ReadLine ();
temp=temp.Substring (temp.IndexOf("=")+1);
istrue1=bool.Parse (temp);
temp=sr.ReadLine ();
temp=temp.Substring (temp.IndexOf("=")+1);
istrue2=bool.Parse (temp);
temp=sr.ReadLine ();
temp=temp.Substring (temp.IndexOf("=")+1);
Opacity=int.Parse (temp);
}
catch(Exception ee )
{
throw ee;
}
}
#endregion
#region 窗体在Windows启动时是否运行主程序
/// <summary>
/// 设置WINDOWS启动时运行主窗体
/// </summary>
public static void SetRunProgram(string path)
{
try
{
RegistryKey rk=Registry.CurrentUser.OpenSubKey (@"Software\Microsoft\Windows\CurrentVersion\Run\",true);
rk.SetValue("XP界面优化师.exe",path);
rk.Close ();
}
catch(Exception ee )
{
throw ee;
}
}
/// <summary>
/// 设置WINDOWS启动时不运行主窗体
/// </summary>
public static void cancelRunProgram()
{
try
{
RegistryKey rk=Registry.CurrentUser.OpenSubKey (@"Software\Microsoft\Windows\CurrentVersion\Run\",true);
rk.SetValue("XP界面优化师.exe","");
rk.Close ();
}
catch(Exception ee )
{
throw ee;
}
}
/// <summary>
/// 是否WINDOWS启动时运行主窗体
/// </summary>
/// <returns></returns>
public static bool isSetRunProgram()
{
try
{
RegistryKey rk=Registry.CurrentUser.OpenSubKey (@"Software\Microsoft\Windows\CurrentVersion\Run\",true);
string temp=(string)rk.GetValue("XP界面优化师.exe");
rk.Close ();
if(temp.Length >0)
{
return true;
}
return false;
}
catch(Exception ee )
{
throw ee;
}
}
#endregion
#region 浏览器
/// <summary>
/// 设置浏览器背景
/// </summary>
/// <param name="path">图片路径</param>
/// <param name="isSame">是否资源浏览器背景也更改</param>
public static void setIEBackBitmap(string path,int browser)
{
RegistryKey rk=Registry.CurrentUser.OpenSubKey (@"Software\Microsoft\Internet Explorer\Toolbar\",true);
if(browser==1)
{
rk.SetValue("BackBitmapIE5",path);
}
else if(browser==2)
{
rk.SetValue ("BackBitmapShell",path);
}
else
{
rk.SetValue("BackBitmapIE5",path);
rk.SetValue ("BackBitmapShell",path);
}
rk.Close ();
}
/// <summary>
/// 取消浏览器背景
/// </summary>
public static void cancelIEBackBitmap()
{
RegistryKey rk=Registry.CurrentUser.OpenSubKey (@"Software\Microsoft\Internet Explorer\Toolbar\",true);
string temp=(string)rk.GetValue ("BackBitmapIE5");
if(temp.Length >0)
{
rk.DeleteValue ("BackBitmapIE5");
}
temp=(string)rk.GetValue ("BackBitmapShell");
if(temp.Length >0)
{
rk.DeleteValue ("BackBitmapShell");
}
rk.Close ();
}
/// <summary>
/// 设置浏览器动画图标
/// </summary>
/// <param name="path">图片路径</param>
public static void setIEBrandBitmap(string path)
{
RegistryKey rk=Registry.CurrentUser.OpenSubKey (@"Software\Microsoft\Internet Explorer\Toolbar\",true);
rk.SetValue ("SmBrandBitmap",path);
rk.Close ();
}
/// <summary>
/// 取消浏览器动画图标
/// </summary>
public static void cancelIEBrandBitmap()
{
RegistryKey rk=Registry.CurrentUser.OpenSubKey (@"Software\Microsoft\Internet Explorer\Toolbar\",true);
string temp=(string)rk.GetValue ("SmBrandBitmap");
if(temp.Length >0)
{
rk.SetValue ("SmBrandBitmap","");
}
rk.Close ();
}
/// <summary>
/// 读取浏览器动画图标
/// </summary>
public static string ReadIEBrandBitmap()
{
RegistryKey rk=Registry.CurrentUser.OpenSubKey (@"Software\Microsoft\Internet Explorer\Toolbar\",true);
string temp=(string)rk.GetValue ("SmBrandBitmap");
rk.Close ();
return temp;
}
/// <summary>
/// 设置浏览器标题的文字
/// </summary>
/// <param name="path">标题文字</param>
public static void setIECaption(string caption)
{
RegistryKey rk=Registry.CurrentUser.OpenSubKey (@"Software\Microsoft\Internet Explorer\Main\",true);
rk.SetValue ("Window Title",caption);
rk.Close ();
RegistryKey rk2=Registry.CurrentUser.OpenSubKey (@"Software\Microsoft\Outlook Express\",true);
rk2.SetValue ("WindowTitle",caption);
rk2.Close ();
}
/// <summary>
/// 读取浏览器标题的文字
/// </summary>
public static string ReadIECaption()
{
RegistryKey rk=Registry.CurrentUser.OpenSubKey (@"Software\Microsoft\Internet Explorer\Main\",true);
string temp=(string)rk.GetValue ("Window Title");
rk.Close ();
return temp;
}
/// <summary>
///得到IE右键菜单列表
/// </summary>
/// <returns></returns>
public static string getIERightMenu()
{
RegistryKey rk=Registry.CurrentUser.OpenSubKey (@"Software\Microsoft\Internet Explorer\MenuExt\",true);
string[] tt=rk.GetSubKeyNames();
rk.Close ();
string returnString ="";
foreach (string temp in tt)
{
returnString+=temp+"|and|";
}
return returnString;
}
/// <summary>
/// 删除IE右键菜单
/// </summary>
public static void DeleteIERightMenu(string MenuName)
{
RegistryKey rk=Registry.CurrentUser.OpenSubKey (@"Software\Microsoft\Internet Explorer\MenuExt\",true);
rk.DeleteSubKey(MenuName,true);
rk.Close ();
}
/// <summary>
/// 设置缺省主页
/// </summary>
/// <param name="page">主页地址</param>
public static void setHomePage(string page)
{
RegistryKey rk=Registry.CurrentUser.OpenSubKey (@"Software\Microsoft\Internet Explorer\Main\",true);
rk.SetValue ("Start Page",page);
rk.Close ();
}
/// <summary>
/// 得到当前主页
/// </summary>
/// <returns>返回主页地址</returns>
public static string getHomePage()
{
RegistryKey rk=Registry.CurrentUser.OpenSubKey (@"Software\Microsoft\Internet Explorer\Main\",true);
string temp=(string)rk.GetValue ("Start Page");
rk.Close ();
return temp;
}
/// <summary>
/// 设置IE浏览器全屏
/// </summary>
public static void setIEBrowserFullScreen()
{
RegistryKey rk=Registry.CurrentUser.OpenSubKey (@"Software\Microsoft\Internet Explorer\Main\",true);
rk.SetValue("FullScreen","yes");
rk.Close ();
}
/// <summary>
/// 取消IE浏览器全屏
/// </summary>
public static void cancelIEBrowserFullScreen()
{
RegistryKey rk=Registry.CurrentUser.OpenSubKey (@"Software\Microsoft\Internet Explorer\Main\",true);
rk.SetValue("FullScreen","no");
rk.Close ();
}
/// <summary>
/// 清除IE浏览器访问网站的历史记录
/// </summary>
public static void ClsIEhistory()
{
RegistryKey rk=Registry.CurrentUser.OpenSubKey (@"Software\Microsoft\Internet Explorer\TypedURLs\",true);
string [] temp =rk.GetValueNames();
foreach(string tt in temp)
{
rk.DeleteValue(tt,true);
}
rk.Close ();
}
#endregion
#region 密码存取加密
/// <summary>
/// 保存密码
/// </summary>
/// <param name="pass">加密过的密码</param>
public static void setPassword(string pass)
{
try
{
RegistryKey rk=Registry.LocalMachine.OpenSubKey (@"Software\Microsoft\Windows\",true);
rk.SetValue("sgpassword",pass);
rk.Close ();
}
catch(Exception ee )
{
throw ee;
}
}
/// <summary>
/// 得到加密过的密码
/// </summary>
/// <returns>返回加密过的密码</returns>
public static string getPassword()
{
try
{
RegistryKey rk=Registry.LocalMachine.OpenSubKey (@"Software\Microsoft\Windows\",true);
string temp=(string)rk.GetValue("sgpassword");
rk.Close ();
return temp;
}
catch(Exception ee )
{
throw ee;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -