■ 用VC++对IE浏览器进行高级操作
————————————————以下为程序代码—————————————
------------WriteReg()函数的主要内容:-----------
void CTestView::WriteReg()
{
//建立上下文菜单
HKEY phkResult;
LPCTSTR lpSubKey = "Software\\Microsoft\\Internet Explorer\\MenuExt";
if (ERROR_SUCCESS == RegCreateKeyEx(HKEY_CURRENT_USER, lpSubKey, 0, "", REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &phkResult, 0))
{
CString keyValue = GetAppPath() + "MySelf.htm";
RegSetValue(phkResult, "我们自己的上下文菜单(&W)", REG_SZ, keyValue, keyValue.GetLength());
}
//建立工具菜单
lpSubKey = "Software\\Microsoft\\Internet Explorer\\Extensions\\{32204547-1C47-11d5-A413-00A00CC191CF}";
if (ERROR_SUCCESS == RegCreateKeyEx(HKEY_LOCAL_MACHINE, lpSubKey, 0, "", REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS,NULL,&phkResult,0))
{
HKEY hResult;
RegOpenKeyEx(HKEY_LOCAL_MACHINE, lpSubKey, 0, KEY_ALL_ACCESS, &hResult);
CString type = "{1FBA04EE-3024-11d2-8F1F-0000F87ABD16}";
RegSetValueEx(hResult, "CLSID", 0, REG_SZ, (const unsigned char *)((LPCSTR)type), type.GetLength());
type="&MyTest"; //MenuText
RegSetValueEx( hResult, "MenuText", 0, REG_SZ, (const unsigned char *)((LPCSTR)type), type.GetLength());
type="我们自己的测试程序"; //MenuStatusBar
RegSetValueEx( hResult, "MenuStatusBar", 0, REG_SZ, (const unsigned char *)((LPCSTR)type), type.GetLength()); 0
type=GetAppPath()+"Test.exe"; //Exec
RegSetValueEx( hResult, "Exec", 0, REG_SZ, (const unsigned char *)((LPCSTR)type), type.GetLength());
//工具栏按钮
type="MyTest"; //ButtonText
RegSetValueEx( hResult, "ButtonText", 0, REG_SZ, (const unsigned char *)((LPCSTR)type), type.GetLength());
type=GetAppPath()+"\\Test.exe,128"; //Icon
RegSetValueEx( hResult, "Icon", 0, REG_SZ, (const unsigned char *)((LPCSTR)type), type.GetLength());
type=GetAppPath()+"\\Test.exe,128"; //HotIcon
RegSetValueEx( hResult, "HotIcon", 0, REG_SZ, (const unsigned char *)((LPCSTR)type), type.GetLength());
type="Yes"; //Default Visible
RegSetValueEx( hResult, "Default Visible", 0, REG_SZ, (const unsigned char *)((LPCSTR)type), type.GetLength());
RegCloseKey( hResult );
}
}
------------GetAppPath()-----------------
CString CTestView::GetAppPath()
{
TCHAR pathtemp[255];
GetModuleFileName(NULL,pathtemp,255);
CString path = pathtemp;
int i = path.ReverseFind('\\');
path = path.Left(i+1);
return path;
}
----------------MySelf.htm---------------
var op = new String("http://www.tsinghua.edu.cn/")
open(op)
----------------text.exe----------------
void CIEcontext::AddContext()
{
// TODO: Add your dispatch handler code here
WinExec("c:\\test\\debug\\test.exe", SW_SHOW);
}
--------------修改后的MySelf.htm------------
set IeP=CreateObject("AddIEFun.IEcontext")
if err0 then
msgbox("错误!")
else
IeP. AddContext()
end if