[译]Internet Explorer皮肤管理器
By robot-v1.0
本文链接 https://www.kyfws.com/applications/internet-explorer-skin-manager-zh/
版权声明 本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
- 7 分钟阅读 - 3039 个词 阅读量 0[译]Internet Explorer皮肤管理器
原文地址:https://www.codeproject.com/Articles/2411/Internet-Explorer-Skin-Manager
原文作者:Manish Hatwalne
译文由本站 robot-v1.0 翻译
前言
An article explaining how to create a utility to manage Internet Explorer skin
解释如何创建实用程序来管理Internet Explorer皮肤的文章
介绍(Introduction)
从上面的快照中可以看到,Internet Explorer(IE 5和更高版本)使您可以使用位图作为IE工具栏的外观/墙纸,只是使其变得更有趣.这个微型实用程序允许您使用基于对话框的便捷应用程序设置/删除IE外观.在此过程中,我们使用以下方法深入研究Windows Registry编程(As you can see in the snapshot above, Internet Explorer (IE version 5 and above) lets you use a bitmap as a skin/wallpaper for the IE toolbar,just to make it a bit more interesting. This tiny utility allows you set/remove IE skin with aconvenient dialog based application. In the process, we delve into Windows Registry programming using) CRegKey
类.(class.)
该实用程序是一个基于对话框的简单应用程序,如上所示,具有纯原始的GUI.可以轻松地将代码分为上述按钮的处理程序.本文的其余部分将讨论相关代码段的重要步骤.(The utility is a simple dialog based application, with plain vanilla GUI as you can see above.The code can be easily divided into the handlers of the buttons shown above. Rest of the article will discuss the important steps with the relevant code snippets.)
选择位图(Choosing a bitmap)
的(The) OnChoose()
按钮"选择…“的处理程序将打开文件打开对话框,并将过滤器设置为-位图文件,因为.bmp文件是IE外观允许的唯一文件. IE皮肤/墙纸不支持其他图像格式,例如JPEG和GIF.此函数获取用户选择的文件的路径并进行设置(handler for button “Choose…” opens a file open dialog with filter set as - Bitmap Files, as .bmp files are the only files allowed for IE skins. Other image formats such asJPEG and GIF are not supported for IE skin/wallpaper. This function gets the path of the file selected by the user and sets) m_szFilePath
达到这个值.它还在只读编辑框中显示文件路径.的代码(to this value. It also displays the file path in the read only edit box. The code for) OnChoose()
是-(is -)
void CIESkinDlg :: OnChoose()
{
//open a file dialog with only BMP files filter,
//other formats not allowed
LPCTSTR lpszFilter = "Bitmap Files (*.bmp)|*.bmp||";
CFileDialog dlgFile(TRUE,NULL,NULL,OFN_FILEMUSTEXIST|OFN_EXPLORER,
lpszFilter,this);
if(IDOK == dlgFile.DoModal())
{
m_szFilePath = dlgFile.GetPathName();
//display file path in the edit box
SetDlgItemText(IDC_EDIT,m_szFilePath);
}
}
将位图设置为外观(Set bitmap as a skin)
若要将所选位图文件设置为Internet Explorer的外观,必须将所选文件的路径指定为注册表值的值数据(To set selected bitmap file as a skin for Internet Explorer, you must specify path of theselected file as a value data for the registry value) BackBitmap
在注册表项下-(under the registry key -)
HKEY_CURRENT_USER
\Software
\Microsoft
\Internet Explorer
\Toolbar
使用类完成注册表修改(The registrymodifications are done using the class) CRegKey
,它提供了在系统注册表中操作值的方法.请注意,您需要包括(, which provides methods for manipulating values in the system registry. Note that, you need to include)*atlbase.h(atlbase.h)*您代码中要使用的头文件(header file in your code to use) CRegKey
类.(class.)
功能(The function) SetIESkin()
将位图设置为外观.反过来,此功能由(sets the bitmap as skin. This function in turnis invoked by the) OnSet()
“设置皮肤"按钮的处理程序.该函数打开所需的注册表项,设置值(handler of the “Set Skin” button. The function opens therequired registry key, sets value of) BackBitmap
至(to) m_szFilePath
,这是用户选择的文件,最后关闭该键.代码 -(, which is the file selected by the user, and in the end closes the key. The code -)
BOOL CIESkinDlg :: SetIESkin()
{
LONG lResult = 0;
CRegKey reg;
//open the required registry key
LPCTSTR lpszKey = "Software\\Microsoft\\Internet Explorer\\Toolbar";
lResult = reg.Open(HKEY_CURRENT_USER,lpszKey);
//check if opened successfully
if(ERROR_SUCCESS != lResult)
{
return FALSE;
}
//set the value
lResult = reg.SetValue(m_szFilePath,"BackBitmap");
if(ERROR_SUCCESS != lResult)
{
return FALSE;
}
//done, close and return success
reg.Close();
return TRUE;
}
让我们来看看一些(Let’s look into some) CRegKey
现在功能,功能(functions now, the function) CRegKey::Open
打开指定的键并设置(opens the specified key and sets) m_hKey
到此键的句柄.原型是-(to the handle of this key. The prototype is -)
LONG Open( HKEY hKeyParent, LPCTSTR lpszKeyName,
REGSAM samDesired = KEY_ALL_ACCESS )
hKeyParent
-它是当前打开键的句柄或预定义的保留句柄值之一,例如-(- It is a handle to a currently open key or one of the predefined reserved handle values such as -)HKEY_CURRENT_USER,
HKEY_LOCAL_MACHINE
等等(etc.)lpszKeyName
-它指定要打开的键的名称.此名称必须是的子项(- It specifies the name of a key to be opened. This name must be a sub-key of)hKeyParent
.(.)samDesired
-密钥的安全性访问.与此相关,允许读取或写入注册表项.默认值为(- The security access for the key. Depending on this, reading or writing of the registry key is permitted. The default value is)KEY_ALL_ACCESS
.其他值包括-(. The other values include -)KEY_WRITE
,(,)KEY_READ
和(and)KEY_QUERY_VALUE
.如果您的应用程序仅需要读取注册表值,则可能需要(. If your application only requires to read the registry values, you would probably want)KEY_QUERY_VALUE
要么(or)KEY_READ
访问.(access.) 这里使用的另一个功能是(Another function used here is)LONG SetValue( DWORD dwValue, LPCTSTR lpszValueName )
,它将数据存储在打开的注册表项的指定值字段中.如果在该特定子项下不存在值名称,则会创建该值名称以存储数据.这个版本的(,which stores data in the specified value field of an open registry key. If the value name does not existunder that particular sub-key, it is created for storing the data. This version of)SetValue
用途(uses)m_hKey
作为打开键.(as the open key.)
功能(The function) LONG Close( )
合上钥匙,松开(closes the key, releasing the) m_hKey
成员句柄并将其设置为(member handle and sets it to) NULL
.关闭密钥后,其注册表数据将写入(刷新)到硬盘中.如果您的应用程序必须将注册表数据显式写入硬盘,则可以调用(. When the key is closed, its registry data is written (flushed) to the hard disk. If your application must explicitly write registry data to the hard disk, you can call the) RegFlushKey
Win32功能.(Win32 function.)
所有这些函数返回(All these functions return) ERROR_SUCCESS
如果成功,否则它们将返回错误值.您可以使用Win 32(if successful, or they return an error valueotherwise. You can use the Win 32) FormatMessage
与(function with the) FORMAT_MESSAGE_FROM_SYSTEM
标志以获取错误的一般描述.(flag to get a generic description of the error.)
去除皮肤(Removing the skin)
要从IE删除皮肤,您需要删除注册表值(To remove the skin from IE you need to delete the registry value) BackBitmap
,它是先前使用函数设置的(,which was set earlier using the function) SetIESkin()
.这是通过功能完成的(. This is done by the function) RemoveIESkin()
,然后由(, which in turn is invoked by the) OnRemove()
“删除皮肤"按钮的处理程序.(handler ofthe “Remove Skin” button.)
的(The) RemoveIESkin()
功能打开所需的键,删除(function opens the required key, deletes the) BackBitmap
从系统注册表中找到密钥的值,最后关闭密钥.成功删除该值将清除IE工具栏.如果找不到要删除的值,则函数返回(value of the key from the system registry, and in the end closes the key.Successful deletion of this value will clear the IE toolbar. If the value to be deleted is not found, the function returns) FALSE
,指示错误.代码 -(, indicating error. The code -)
BOOL CIESkinDlg :: RemoveIESkin()
{
LONG lResult = 0;
CRegKey reg;
//open the required registry key
LPCTSTR lpszKey = "Software\\Microsoft\\Internet Explorer\\Toolbar";
lResult = reg.Open(HKEY_CURRENT_USER,lpszKey);
//check if opened successfully
if(ERROR_SUCCESS != lResult)
{
return FALSE;
}
//delete the value "BackBitmap" from toolbar
lResult = reg.DeleteValue("BackBitmap");
//check if deleted successfully
if(ERROR_SUCCESS != lResult)
{
return FALSE; //perhaps value not found, if skin is not set
}
//done, return success
reg.Close();
return TRUE;
}
功能(The function) CRegKey::DeleteValue
实际上删除由以下项标识的键的值字段(actually deletes value field of the key identified by) m_hKey
,依次由(, which in turn is set by) CRegKey::Open
.原型(.The prototype of) CRegKey::DeleteValue
是-(is -)
LONG DeleteValue( LPCTSTR lpszValue )
该函数接受参数(The function accepts parameter) lpszValue
,它指定要删除的值字段.如果成功删除该值,该函数将返回(, which specifies the value field tobe removed. If the value is deleted successfully, the function returns) ERROR_SUCCESS
,否则返回错误值.如果参数表示的值(,or returns an error value otherwise. If the value denoted by parameter) lpszValue
找不到,该函数返回错误值.收到此错误值后,(is not found,the function returns an error value. On receiving this error value, the) RemoveIESkin()
函数返回(function returns) FALSE
表示没有删除注册表值.(indicating that the deletion of registry value did not take place.)
而已!(That’s it!)
真!这样就结束了该实用程序的所有重要代码.其余的零碎部分可以在源代码中找到.使用该实用程序开始尝试各种bmp文件后,您就可以使IE看起来非常酷.另外,作为副作用,您的Outlook Express也将开始炫耀这种新皮肤.(Really! That ends all the important code of this utility. Rest of the bits and pieces can be found in the source code. Once you start experimenting with various bmp files using this utility, you can make your IE look really cool. Also, as a side effect, your outlook express will also start flauntingthis new skin.)
您可以使用此代码开发完整的IE定制实用程序,通过设置适当的注册表值,该实用程序可以具有定制标题,定制旋转徽标,品牌徽标等.有关这些注册表设置的详细信息可以从MSDN站点获得.快乐的编码和调试;)(You can use this code to develop a full-fledged IE customization utility, which could have a custom title, custom revolving logo, brand logo etc. by setting the appropriate registry values. The details about these registry settings can be obtained form the MSDN site. Happy coding and debugging ;))
许可
本文以及所有相关的源代码和文件均已获得The Code Project Open License (CPOL)的许可。
VC7.0 C++ HTML VC6 Windows Win2K IE5.5 Visual-Studio IE6.0 Dev 新闻 翻译