将IE的右键搬到opera里

IE的右键大部分是去调用一个html文件,里面写了一个脚本来调用程序,本文通过研究脚本来使opera也可以调用程序.
一.迅雷
查找注册表"HKEY_CURRENT_USER/Software/Microsoft/Internet Explorer/MenuExt/使用迅雷下载"
其中   默认=D:/Program Files/Green Files/Thunder Network/Thunder/Program/geturl.htm
表明去调用 D:/Program Files/Green Files/Thunder Network/Thunder/Program/geturl.htm
打开,内容如下
<script language="javascript">


function AddLink(Url,Info,Location,strCID,strStatUrl,strCookie)
{
 if (Url != "")
 {
  if (Info == "")
  {
   Info = "unknown";
  }
  var ThunderAgent = new ActiveXObject("ThunderAgent.Agent");
  
  if (strCID != "")
  {
   if (strStatUrl != "")
   {
    
    ThunderAgent.AddTask5(Url, "", "", Info, Location, -1, 0, -1,  strCookie, strCID, strStatUrl, 1, "", -1);
   }
   else
   {
    ThunderAgent.AddTask5(Url, "", "", Info, Location, -1, 0, -1,  strCookie, strCID, "", 1, "", -1);
   }
  }
  else
  {
   ThunderAgent.AddTask5(Url, "", "", Info, Location,-1,0,-1,strCookie,"","", 1, "", -1);
  }
  ThunderAgent.CommitTasks2(1);
 }
}

function OnContextMenu()
{
 var srcEvent = external.menuArguments.event;
 var EventElement;
 
 if(typeof(srcEvent.clientX) == "undefined")
 {
  EventElement = external.menuArguments.document.elementFromPoint ( srcEvent.pointerX, srcEvent.pointerY );
 }
 else
 {
  EventElement = external.menuArguments.document.elementFromPoint ( srcEvent.clientX, srcEvent.clientY );
 }
  
  

 var strDownloadPage = external.menuArguments.location;
 var theDownloadPage = external.menuArguments.document.getElementById("thunder_down_pageurl");
 
 if (theDownloadPage != null)
 {
  strDownloadPage = theDownloadPage.value;
 }
 

 var strStatPage = "";
 var theStatPage = external.menuArguments.document.getElementById("thunder_stat_pageurl");
 if (theStatPage != null)
 {
  strStatPage = theStatPage.value;
 }

 var strCID = ""
 var theCID = external.menuArguments.document.getElementById("thunder_cid");
 if (theCID != null)
 {
  strCID = theCID.value;
 }
 var srcAnchor;

 if (srcEvent.type == "MenuExtAnchor")
 {

  srcAnchor = EventElement;

  do
  {
   srcAnchor=srcAnchor.parentElement;
  }while(typeof(srcAnchor)=="HTMLAnchorElement");
  
  AddLink(srcAnchor.href,srcAnchor.innerText,strDownloadPage, strCID, strStatPage,external.menuArguments.document.cookie);
 }
 else if (srcEvent.type == "MenuExtImage")
 {
  if (typeof(EventElement) == "HTMLAreaElement")
  {
   AddLink(EventElement.href,EventElement.Alt,strDownloadPage, strCID, strStatPage,external.menuArguments.document.cookie);
  }
  else
  {
   var srcImage = EventElement;
   var srcAnchor = srcImage.parentElement;
   do
   {
    srcAnchor=srcAnchor.parentElement;
    if (typeof(srcAnchor) == "undefined")
    {
     AddLink(srcImage.href,srcImage.Alt,strDownloadPage, strCID, strStatPage,external.menuArguments.document.cookie);
     return;
    }
   }while(typeof(srcAnchor) == "HTMLAnchorElement");
   AddLink(srcAnchor.href,srcImage.Alt,strDownloadPage, strCID, strStatPage);
  }
 } 
 else if (srcEvent.type == "MenuExtUnknown")
 {
 srcAnchor = EventElement;
 if(srcAnchor != null && srcAnchor.tagName != null && srcAnchor.tagName.toLowerCase() == "a")
     {
         AddLink(srcAnchor.href,srcAnchor.innerText,strDownloadPage, strCID, strStatPage,external.menuArguments.document.cookie);
     }
     else
     {
         while(srcAnchor != null && srcAnchor.tagName != null && srcAnchor.tagName.toLowerCase() != "a")
         {
             srcAnchor = srcAnchor.parentElement;
             if(srcAnchor != null && srcAnchor.tagName != null && srcAnchor.tagName.toLowerCase() == "a")
             {
                 AddLink(srcAnchor.href,srcAnchor.innerText,strDownloadPage, strCID, strStatPage,external.menuArguments.document.cookie);
                 return;
             }
         }
   
         if(EventElement != null && EventElement.tagName != null)
         {
             AddLink(EventElement.href,EventElement.innerText,strDownloadPage, strCID, strStatPage,external.menuArguments.document.cookie);
         }
         else
         {
             alert("无法识别的超级链接信息");
         }
     }
 }
 else
 {
  
 }
}

 


OnContextMenu();

</script>

注意主要内容,它是先生成一个com对象名为"ThunderAgent ",com注册名称为"ThunderAgent.Agent"(很重要).
  var ThunderAgent = new ActiveXObject("ThunderAgent.Agent");
然后调用ThunderAgent 的函数AddTask5,CommitTasks2(很重要)
ThunderAgent.AddTask5(Url, "", "", Info, Location, -1, 0, -1,  strCookie, strCID, "", 1, "", -1);
ThunderAgent.CommitTasks2(1);
脚本分析完毕,开始编程
打开VC,新建一个win32控制台程序,设置为UNICODE环境
代码:
//author: hgyxb
//Email: xiaolan1980@gmail.com

#include "stdafx.h"
#include <windows.h>
using namespace std;
#ifdef   _UNICODE  
#define   tstring   wstring  
#else  
#define   tstring   string  
#endif 


//设置迅雷com路径
#define ActiveXPath "D:/Program Files/Green Files/Thunder Network/Thunder/ComDlls/ThunderAgent.dll"
#import  ActiveXPath no_namespace
//设置迅雷com的对象类型
typedef IAgent CActiveX;
//设置com的对象名称
tstring g_strObjName=L"ThunderAgent.Agent";

CActiveX* InitActiveX(tstring &strObjName)
{
 CLSID clsid;
 HRESULT hr = ::CLSIDFromProgID(strObjName.c_str(), &clsid);
 if(SUCCEEDED(hr))
 {

  CActiveX *pAgent = NULL;
  hr = ::CoCreateInstance(clsid, NULL, CLSCTX_INPROC_SERVER,__uuidof(CActiveX),
   (void **)&pAgent);
  if(SUCCEEDED(hr))
  {
   return pAgent;
  }else
  {
   return NULL;
  }
 }else
 {
  return NULL;
 }
}


wstring ConvertAnsiToUnicode(const string strAnsi)
{
 wstring strUnicode;
 int len=MultiByteToWideChar(CP_ACP, 0, strAnsi.c_str(), -1, NULL,0);
 PWSTR wsz=new WCHAR[len+1];
 wsz[len]=0;
 MultiByteToWideChar(CP_ACP, 0, strAnsi.c_str(), -1, wsz, len);
 strUnicode=wsz;
 delete []wsz;
 return  strUnicode;
}

//获得剪切板内容
tstring GetClipboardText()
{
 tstring str=L"";
 CHAR  * pBuf;
 HWND hWnd;
 hWnd= GetDesktopWindow();
 if(OpenClipboard(hWnd))
 {
  if(IsClipboardFormatAvailable(CF_TEXT)) // 判定剪切板数据格式
  {
   HANDLE hClip;
   hClip=::GetClipboardData(CF_TEXT);
   pBuf=(char*)GlobalLock(hClip);
   GlobalUnlock(hClip);
   if (pBuf !=NULL)
   {
    str=ConvertAnsiToUnicode(string(pBuf));
   }
  }
  CloseClipboard();
 }
 return str;
}


#pragma comment( linker, "/subsystem:/"windows/" /entry:/"wmainCRTStartup/"" )//隐藏窗口
int _tmain(int argc, _TCHAR* argv[])
{
 ::CoInitialize(NULL);
 CActiveX *obj=InitActiveX(g_strObjName);
 if(obj == NULL)
 {
  ::CoUninitialize();
  MessageBox(NULL,L"无法启动程序,请检查程序是否安装正确!",L"警告",MB_YESNO);
  return 0;
 }
 /

 //在这里你可以添加你的代码了
 if (argc>1)
 {
  obj->AddTask(argv[1],"","","","",-1,0,-1);//argv[1]为程序接收到的参数
  obj->CommitTasks();
  obj->Release(); 
 }
 //添加代码结束

 /
 ::CoUninitialize();
 return 0;
}

1.其中迅雷com的路径根据经验找,一般和com名相似.
2.com的对象名称从脚本中获得.
3.IAgent这个类型是在编译程序后,Debug目录下会出现thunderagent.tlh文件(import "ThunderAgent.dll"后会出现),打开thunderagent.tlh,里面全是
定义,定义类型为IAgent类,所以用IAgent.
4.以下代码根据脚本和thunderagent.tlh文件里的定义并且试验然后如此使用
obj->AddTask(argv[1],"","","","",-1,0,-1);//argv[1]为程序接收到的参数
obj->CommitTasks();
obj->Release(); 

将编译出的xunlei_opera.exe文件放到opera安装目录下.
编辑Opera/profile/menu/standard_menu (1).ini
在[Link Popup Menu]中添加
Item,"迅雷"=Execute Program,"xunlei_opera.exe","%l"
下载xunlei_opera.exe
http://www.91files.com/?GJMFXIT9UCJPFTL52DY1

下面再给一个案例,添加右键调用"文语通"朗读
ir_Link.htm(对应IE右键"使用“文语通”朗读链接")内容
<script language="VBScript">
'Great thanks to Vladimir Romanov(Author of ReGet Pro)
'Download selected link

Sub AddLink(Url,Info)
 On Error Resume Next
 set irComCache=CreateObject("IReaderCom.IReader")
 if err<>0 then
  MsgBox("FlashGet not properly installed!"+ vbCrLf+"Please install FlashGet again")
 else
  call irComCache.PlayUrl(Url)
        end if
end sub

Sub OnContextMenu()
 'set srcEvent = external.menuArguments.event
 set EventElement = external.menuArguments.document.elementFromPoint ( srcEvent.clientX, srcEvent.clientY )
 if srcEvent.type = "MenuExtAnchor" then
  set srcAnchor = EventElement
  do until TypeName(srcAnchor)="HTMLAnchorElement"
   set srcAnchor=srcAnchor.parentElement
  Loop
  Call AddLink(srcAnchor.href,srcAnchor.innerText)
 elseif srcEvent.type="MenuExtImage" then
  if TypeName(EventElement)="HTMLAreaElement" then
   Call AddLink(EventElement.href,EventElement.Alt)
  else
   set srcImage = EventElement
   set srcAnchor = srcImage.parentElement
   do until TypeName(srcAnchor)="HTMLAnchorElement"
    set srcAnchor=srcAnchor.parentElement
    if TypeName(srcAnchor)="Nothing" then
     call AddLink(srcImage.href,srcImage.Alt)
     exit sub
    end if
   Loop
   Call AddLink(srcAnchor.href,srcImage.Alt)
  end if
 elseif srcEvent.type="MenuExtUnknown" then
  set srcAnchor = EventElement
  do until TypeName(srcAnchor)="HTMLAnchorElement"
   set srcAnchor=srcAnchor.parentElement
   if TypeName(srcAnchor)="Nothing" then
    Call AddLink(EventElement.href,EventElement.innerText)
    exit sub
   end if
  Loop
  Call AddLink(srcAnchor.href,srcAnchor.innerText)
 elseif 1=1 then
  MsgBox("Unknown Event Source """ + srcEvent.type + """" + vbCrLf + "Please send description of error to http://support.iflytek.com/desktop")
 end if
end sub


call OnContextMenu()

</script>

ir_Select.htm(对应IE右键"使用“文语通”朗读选定内容")内容
 <SCRIPT LANGUAGE="JavaScript">
     var irComCache = new ActiveXObject("IReaderCom.IReader")
     var parentwin = external.menuArguments;
     var doc = parentwin.document;
     var sel = doc.selection;
     var rng = sel.createRange();
     var str = new String(rng.text);
   if( str!="")
   {
     irComCache.PlayContent(str);
   }
</SCRIPT>


VC代码:
//author: hgyxb
//Email: xiaolan1980@gmail.com

#include "stdafx.h"
#include <windows.h>
using namespace std;
#ifdef   _UNICODE  
#define   tstring   wstring  
#else  
#define   tstring   string  
#endif 


//将外部程序的com组件(即dll文件)路径代替D:/Program Files/iFly Info Tek/iReader2.0/IReaderCom.dll
#define ActiveXPath "D:/Program Files/iFly Info Tek/iReader2.0/IReaderCom.dll"
#import  ActiveXPath no_namespace
//将类型IIReader改为外部程序的类型
typedef IIReader CActiveX;
//将外部程序com组件的名称代替IReaderCom.IReader
tstring g_strObjName=L"IReaderCom.IReader";

CActiveX* InitActiveX(tstring &strObjName)
{
 CLSID clsid;
 HRESULT hr = ::CLSIDFromProgID(strObjName.c_str(), &clsid);
 if(SUCCEEDED(hr))
 {

  CActiveX *pAgent = NULL;
  hr = ::CoCreateInstance(clsid, NULL, CLSCTX_INPROC_SERVER,__uuidof(CActiveX),
   (void **)&pAgent);
  if(SUCCEEDED(hr))
  {
   return pAgent;
  }else
  {
   return NULL;
  }
 }else
 {
  return NULL;
 }
}

wstring ConvertAnsiToUnicode(const string strAnsi)
{
 wstring strUnicode;
 int len=MultiByteToWideChar(CP_ACP, 0, strAnsi.c_str(), -1, NULL,0);
 PWSTR wsz=new WCHAR[len+1];//strUnicode.GetBufferSetLength(len+1);
 wsz[len]=0;
 MultiByteToWideChar(CP_ACP, 0, strAnsi.c_str(), -1, wsz, len);
 strUnicode=wsz;
 delete []wsz;
 return  strUnicode;
}

//获得剪切板内容
tstring GetClipboardText()
{
 tstring str=L"";
 CHAR  * pBuf;
 HWND hWnd;
 hWnd= GetDesktopWindow();
 if(OpenClipboard(hWnd))
 {
  if(IsClipboardFormatAvailable(CF_TEXT)) // 判定剪切板数据格式
  {
   HANDLE hClip;
   hClip=::GetClipboardData(CF_TEXT);
   pBuf=(char*)GlobalLock(hClip);
   GlobalUnlock(hClip);
   if (pBuf !=NULL)
   {
    str=ConvertAnsiToUnicode(string(pBuf));
   }
  }

  CloseClipboard();
 }
 return str;
}


#pragma comment( linker, "/subsystem:/"windows/" /entry:/"wmainCRTStartup/"" )//隐藏窗口
int _tmain(int argc, _TCHAR* argv[])
{
 ::CoInitialize(NULL);
 CActiveX *obj=InitActiveX(g_strObjName);
 if(obj == NULL)
 {
  ::CoUninitialize();
  MessageBox(NULL,L"无法启动程序,请检查程序是否安装正确!",L"警告",MB_YESNO);
  return 0;
 }
 /

 //在这里你可以添加你的代码了
           //如果有参数,那就播放网页链接,否则播放剪切板中的内容
 if (argc>1)
 {
  obj->PlayUrl(argv[1]);
 }else
 {
  tstring strContent=GetClipboardText();
  if (strContent.length() != 0)
  { 
   obj->PlayContent(strContent.c_str());
  }
 }

 //添加代码结束

 /
 ::CoUninitialize();
 return 0;
}

将编译出的ireader_opera.exe文件放到opera安装目录下.
编辑Opera/profile/menu/standard_menu (1).ini
在[Link Popup Menu]中添加
Item,"朗读链接"=Execute program, "ireader_opera.exe","%l"
在[Hotclick Popup Menu]添加
Item,  "用iRead朗读"=Copy&Execute program,"ireader_opera.exe"
下载ireader_opera
http://www.91files.com/?9LG7WARNHCZGO98GZA7Y

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值