从Outlook窗口拖放到.Net中的Application .EXE文件(或Icon) [英] Drag and Drop from Outlook Window to Application .EXE file (or Icon) in .Net

查看:162
本文介绍了从Outlook窗口拖放到.Net中的Application .EXE文件(或Icon)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

之前已经提到过,但是我看到的方法,我不能得到我想要发生的事情。目前,我有一个Windows窗体,如果我运行.EXE(并提出表单本身),我可以从Outlook Outlook中删除电子邮件没有问题。但是,我正在寻找的是在用户将邮件从Outlook直接删除到.EXE文件上的图标时具有此功能。我可以做到这一点,如果我保存文件在本地,并将其放在图标上,但直接从Outlook,我得到一个圆圈与一条线通过它。有没有一个财产,我需要设置在应用程序,使这项工作。我使用这段代码将消息放到表单窗口上。

This has been asked before, but with the methods I have seen, I cannot get what I want to happen. Currently, I have a Windows Form that if I run the .EXE (and bring up the form itself), I can drop Emails from outlook into it no problem. However, what I am looking for is to have this functionality when a user drops the message directly from Outlook to the Icon on the .EXE file. I can do this fine if I save the file locally and drop it onto the icon, but straight from Outlook, I get a circle with a line through it. Is there a property I need to set on the app to make this work. I used this code to get the dropping the message onto the form window to work.

http://www.codeproject.com/Articles/28209/Outlook-Drag-and-Drop-in-C

这是我写入图标的代码。

This is the code that I wrote that drops onto the Icon.

 static class Program
{
    /// <summary>
    /// The main entry point for the application.
    /// </summary>
    [STAThread]
    static void Main(string[] args)
    {

        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);

        var form = new Form1();

        if (args.Length > 0)
        {
            form.ProcessCommandLine(args[0]);
        }

        Application.Run(form);
    }
}

 public void ProcessCommandLine(string commandLine)
    {
        lstFiles.Items.Clear();

        var fileAttributes = File.GetAttributes(commandLine);
        if (fileAttributes.HasFlag(FileAttributes.Directory))
        {
            ProcessDirectory(commandLine);
        }
        else
        {
            ProcessFile(commandLine);
        }
    }

任何帮助不胜感激,谢谢。 p>

Any help would be appreciated, thank you.

推荐答案

您正在寻找一个 Shell Drop Handler 。如您所发现的那样,.EXE文件的默认放置处理程序接受任何文件作为可替代项目,并自动启动具有删除文件路径的应用程序。 Windows资源管理器不支持其他项目,例如从Outlook直接拖动的邮件或日历对象。 Windows附带的下拉式处理程序的一个例子是,如果将文件拖到ZIP文件上,则在删除文件时自动将该文件添加到ZIP存档。

You are looking to create a Shell Drop Handler. As you have discovered, the default drop handler for .EXE files accepts any file as a droppable item, and it automatically launches the application with the path to the dropped file. Other items, such as an mail or Calendar object being directly dragged from Outlook, is not supported by Windows Explorer directly. One example of a drop handler that is included with Windows is if you drag a file onto a ZIP file, it automatically adds that file to the ZIP archive when you drop.

如果您仍然希望创建自己的拖放处理程序,则可以在任何删除的项目删除任何文件(例如程序的图标,快捷方式等)时执行任何自定义操作。这不是一件简单的任务,而是编写shell扩展通常不推荐使用托管代码(C#或VB)。 (见: http://blogs.msdn.com/ b / oldnewthing / archive / 2006/12/18 / 1317290.aspx

If you still want to create your own drop handler, you can perform any custom action when any dropped item is dropped on any file (such as your program's icon, a shortcut, etc.) This is not a trivial task, and writing shell extensions from managed code (C# or VB) is generally not recommended. (See: http://blogs.msdn.com/b/oldnewthing/archive/2006/12/18/1317290.aspx)

一旦你创建了drop处理程序,这是一个两步的过程:

Once you create your drop handler, it is a two-step process:


  1. 在程序安装过程中,使用唯一的文件扩展名(如.myprogdroptarget)在桌面上创建一个文件。

  2. 注册.myprogdroptarget的放置处理程序,以便该图标成为对象的魔术放置目标。

关于如何在ATL / C ++中创建Drop Handler的一些示例代码,请查看 Microsoft All-In-One代码框架,特别是类 ATLShellExtDragAndDropHandler.cpp

For some sample code on how to create a Drop Handler in ATL/C++, check out the Microsoft All-In-One code framework, specifically the class ATLShellExtDragAndDropHandler.cpp

替代解决方案:

考虑创建一个执行类似功能的Windows桌面小工具。编码应该更简单,因为你不需要挖掘C ++。曾经有一个名为魔术文件夹的Vista小工具被接受作为放置目标的项目,但是我无法再在Windows库中找到它。这是一篇描述它如何工作的文章:

Consider creating a Windows Desktop Gadget that performs similar functionality. The coding should be simpler since you won't have to dig into C++. There was once a Vista gadget called the Magic Folder that accepted items as drop targets, however I can no longer find it on the Windows gallery. Here's an article that described how it worked:

http://www.howtogeek.com/howto/windows-vista/keep-your-vista-desktop-clean-with-the-magic-folder/

这里是一个链接到作者(也许他会分享源代码,如果你很好地问): http://davecra.wordpress.com/

And here is a link to the author (maybe he'll share the source code if you ask nicely): http://davecra.wordpress.com/

这篇关于从Outlook窗口拖放到.Net中的Application .EXE文件(或Icon)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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