【com编程】IE浏览器(右键扩展功能总结版)

         序言:大家是不是莫名其妙,我怎么什么都搀和上两脚。搞起这个高深的COM编程来了。呵呵……这是帮同学做的一个小东西,由于以前拿这个比赛过,今天由于业务需要又用上了,所以又拉我来做一下这个。都是兄弟,放下手中的活帮哥们做了。

         需求:在IE菜单中,添加右键。点击右键调用javaScript,执行相应功能。

         步骤:以管理员身份打开VS2005,新建ATL工程,

动态获取当前位置,并写入注册表中

void OnChange() 
{
    
    WCHAR buf[128];
    GetCurrentDirectory(128,(LPTSTR)buf);

	WCHAR name[14]=L"\\analyse.htm";

    CRegKey key;  
    key.Create(HKEY_CURRENT_USER, _T("Software\\Microsoft\\Internet Explorer\\MenuExt\\&分析")); 

	wcscat(buf,name);

    key.SetStringValue( _T("(默认)"), buf); 
    key.SetDWORDValue(_T("Contexts"),48);
}

ananlyse.htm

<script language="JavaScript">
  var parentwin = external.menuArguments;
  var doc = parentwin.document;
  var sel = doc.selection;
  var rng = sel.createRange();
  var str = encodeURI(new String(rng.text));
  if(0 < str.length)
  {
    var url = "http://10.100.68.1/classify_analyse/query_emotion.php?content=" + str;
    openwindow(url, "情感分析对话框",800,600);
  } else {
    alert("请选择文本内容");
  }
function openwindow(url,name,iWidth,iHeight) {
    var iTop = (window.screen.availHeight - 30 - iHeight) / 2;  //获得窗口的垂直位置; 
    var iLeft = (window.screen.availWidth - 10 - iWidth) / 2;   //获得窗口的水平位置; 
    var customed = "toolbar=no,menubar=no,scrollbars=yes,resizable=yes,location=no,status=no";
    var windowFeatures = "height=" + iHeight + ",innerHeight=" + iHeight + ",width=" + iWidth + ",innerWidth=" + iWidth + ",top=" + iTop + ",left=" + iLeft + "," + customed;
    window.open(url, name, windowFeatures);
}
</script>

注册dll的文件

copy analyse.htm %windir%   
copy db_operation_pop.htm %windir%
regsvr32 sentiment_plugin.dll /s

总之,不容易把相对路径写上,还是用绝对路径简单。


还有好多,不愿意总结了,就把关键的总结上来了。如果感兴趣,可以留言索要相关内容


原文地址:https://www.cnblogs.com/secbook/p/2655016.html