将上下文菜单添加到IE以执行我的程序 [英] Adding context menu to IE to execute my program

查看:169
本文介绍了将上下文菜单添加到IE以执行我的程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何在IE上下文菜单(右键菜单)中添加新项目,以便复制网站中的所选文本,打开我的winform应用程序C#并将文本粘贴到文本框中在我的应用程序中。

I wanted to know how can I add a new item to IE context menu (right click menu), so that the selected text from a website is copied, my winform application C# is opened and the text is pasted into a text box in my application.

推荐答案

您可以在IE标准上下文菜单中添加一个条目来打开您的程序。为此,请按照下列步骤操作:

You can add an entry to IE standard context menu to open your program. To do so, follow these steps:


  1. 打开注册表并转到:

  1. Open registry and go to:

HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\MenuExt


  • 创建一个新密钥,并将密钥名称设置为要在上下文菜单中显示的文本作为名称,例如:打开我的应用程序

    右键单击(默认)并选择修改。 .. 并将值设置为html文件的路径,该文件将包含打开应用程序的命令。例如: C:\ OpenMyApp.html

    Right click on (Default) and choose Modify... and set the value to path of an html file which will contains the command to open your application. For example: C:\OpenMyApp.html

    添加新的 DWORD 值为 Context 并将其值设置为十六进制 11 或十进制 17 。要查看更多选项,请参阅文档。另外在文档中说添加二进制文件但是我尝试了 DWORD 而且它有效。我见过的其他扩展使用 DWORD

    Add a new DWORD value named Context and set it's value to hexadecimal 11 or decimal 17. To see more options read documentation. Also in documentations said to add binary but I tried DWORD instead and it worked. Also other extensions that I've seen use DWORD.

    将此内容用于 C:\ OpenOyMyApp.html

    <script type="text/javascript">
        function getSelectionText(w) {
            var text = "";
            if (w.getSelection) {
                text = w.getSelection().toString();
            } else if (w.document.selection && w.document.selection.type != "Control") {
                text = w.document.selection.createRange().text;
            }
            return text;
        }
    
        var parentwin = external.menuArguments;
        var selection = getSelectionText(parentwin);
        var oShell = new ActiveXObject("Shell.Application");
        var commandtoRun = "C:\\MyApp.exe"; 
        oShell.ShellExecute(commandtoRun,"\""+selection+"\"","","open","1");
    </script>
    


  • 然后将应用程序复制到 C:\就足够了MyApp.exe的。您的应用程序应通过接受 string [] args 作为 Main 入口点的输入参数或使用<$来处理命令行参数C $ C> Environment.GetCommandLineArgs()。然后就足以将参数传递给您的表单并将其显示在文本框中。

  • Then it's enough to copy your application to C:\MyApp.exe. Your application should handle command line arguments by accepting string[] args as input parameters for Main entry point or using Environment.GetCommandLineArgs(). Then it's enough to pass the argument to your form and show it on your text box.

    有关详细信息:

    • Adding Entries to the Standard Context Menu
    • Browser Extensions

    这篇关于将上下文菜单添加到IE以执行我的程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆