C#編程打造自己的IE瀏覽器
2024-07-21 02:25:36
供稿:網友
國內最大的酷站演示中心!
聲明:本文已經放到了天極網站上,這里只是收藏而已。未經許可,不得轉載
ie是現在windows平臺下用的最多的瀏覽器,那么如何用程序來修改ie,打造有自己的特色的ie呢?
我在這里向介紹怎么c#用通過注冊表來修改ie。
首先我們來熟悉一下c#中修改注冊表的方法與函數。在vc#中提供了registry類、registrykey類來實現對注冊表的操作。其中registry類封裝了注冊表的七個基本主健:
registry.classesroot 對應于hkey_classes_root主鍵
registry.currentuser 對應于hkey_current_user主鍵
registry.localmachine 對應于 hkey_local_machine主鍵
registry.user 對應于 hkey_user主鍵
registry.currentconfig 對應于heky_current_config主鍵
registry.dynda 對應于hkey_dyn_data主鍵
registry.performancedata 對應于hkey_performance_data主鍵
registrykey類封裝了對注冊表的基本操作,包括讀取,寫入,刪除。其中讀取的主要函數有:
opensubkey ( string name )方法主要是打開指定的子鍵。
getsubkeynames ( )方法是獲得主鍵下面的所有子鍵的名稱,它的返回值是一個字符串數組。
getvaluenames ( )方法是獲得當前子鍵中的所有的鍵名稱,它的返回值也是一個字符串數組。
getvalue ( string name )方法是指定鍵的鍵值。
寫入的函數有:
createsubkey(string name)方法是增加一個子鍵
setvalue(string name,string value)方法是設置一個鍵的鍵值
刪除的函數:
deletesubkey ( )方法:刪除一個指定的子鍵。
deletesubkeytree ( )方法:
此方法是徹底刪除指定的子鍵目錄,即:刪除該子鍵以及該子鍵以下的全部子鍵。
通過注冊表可以修改ie,在這里我簡單的介紹幾個常用的來實現對ie的修改。
如果我們希望在打開或者關閉ie窗口時,被打開的窗口有動感效果,那么可以打開hkey_ current_user / control panel/ desktop/ windowmetrics鍵,并在右邊的窗口中新建串值"minanimat"與"maxanimat"并設值為"0",為"1",這樣在ie窗口最大最小化切換時有遞變的效果。
如果我們更改為ie的工具欄添加背景那么展開hkey_current_user\ software\microsoft\internet explorer\toolbar鍵值,explorer主鍵下新建一個名為"backbitmap"的字符串值,并將其值修改為事先準備的bmp圖片的完整路徑及文件名;這樣我們就完成了為ie的工具欄添加背景圖片的目的。
用c#編程來實現的方法如下:
1.ie窗口的動感效果
//-------------------------------------
// changeie.cs © 2004 by yudehui
//-------------------------------------
using system;
using microsoft.win32; //對注冊表操作一定要引用這個命名空間
namespace changeie
{
class changeie
{
[stathread]
static void main(string[] args)
{
registrykey pregkey ;
pregkey = registry.currentuser.opensubkey("control panel//desktop//windowmetrics",true);
if (pregkey==null)
{
console.writeline("鍵值不存在");
}
else
{
pregkey.setvalue("minanimate","1");
pregkey.setvalue("maxanimate","1");
console.writeline("修改成功");
}
pregkey. close;
}
}
}
2.改變ie工具欄的背景
//-------------------------------------
// changeie.cs © 2004 by yudehui
//-------------------------------------
using system;
using microsoft.win32; //對注冊表操作一定要引用這個命名空間
namespace changeiebackcolor
{
class changeiebackcolor
{
[stathread]
static void main(string[] args)
{
registrykey pregkey ;
pregkey = registry.currentuser.opensubkey("software//microsoft//internet" +
"explorer//toolbar//explorer ",true);
if (pregkey==null)
{
console.writeline("鍵值不存在");
}
else
{
pregkey.setvalue("backbitmap","c://windows//greenstone.bmp");
console.writeline("修改成功");
}
pregkey.close;
}
}
}
以上兩個簡單的例子只是對ie進行了簡單的設定,相信大家對c#下對注冊表的操作已經有了一定的了解。有興趣的讀者可以自己對ie進行更個性化的修改,以上代碼在windows2003+vs.net2003下調試通過。
注:在對注冊表進行操作有一定的危險性,操作時要先進行備份,以防止誤操作,而導致系統崩潰。