简体   繁体   English

从Outlook窗口拖放到.Net中的应用程序.EXE文件(或图标)

[英]Drag and Drop from Outlook Window to Application .EXE file (or Icon) in .Net

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. 目前,我有一个Windows窗体,如果我运行.EXE(并调出窗体本身),我可以将Outlook中的电子邮件放入其中没问题。 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. 但是,我正在寻找的是当用户将消息直接从Outlook丢弃到.EXE文件上的图标时具有此功能。 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. 如果我在本地保存文件并将其放到图标上,我可以做得很好,但直接从Outlook中,我得到一个带有一条直线的圆圈。 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 http://www.codeproject.com/Articles/28209/Outlook-Drag-and-Drop-in-C

This is the code that I wrote that drops onto the Icon. 这是我写的代码,它落在了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);
        }
    }

Any help would be appreciated, thank you. 任何帮助将不胜感激,谢谢。

You are looking to create a Shell Drop Handler . 您正在寻找创建一个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. 正如您所发现的,.EXE文件的默认删除处理程序接受任何文件作为可放置项,并自动启动具有删除文件路径的应用程序。 Other items, such as an mail or Calendar object being directly dragged from Outlook, is not supported by Windows Explorer directly. Windows资源管理器不直接支持其他项目,例如直接从Outlook拖动的邮件或日历对象。 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. Windows附带的丢弃处理程序的一个示例是,如果将文件拖到ZIP文件上,则在删除时会自动将该文件添加到ZIP存档中。

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. 如果您仍想创建自己的放置处理程序,则可以在任何文件上删除任何放置的项目时执行任何自定义操作(例如程序的图标,快捷方式等)。这不是一项简单的任务,并且编写shell扩展通常不建议使用托管代码(C#或VB)。 (See: http://blogs.msdn.com/b/oldnewthing/archive/2006/12/18/1317290.aspx ) (见: http//blogs.msdn.com/b/oldnewthing/archive/2006/12/18/1317290.aspx

Once you create your drop handler, it is a two-step process: 创建drop handler之后,它分为两步:

  1. During program installation, create a file on the desktop with a unique file extension (such as .myprogdroptarget). 在程序安装期间,使用唯一的文件扩展名(例如.myprogdroptarget)在桌面上创建一个文件。
  2. Register the drop handler for .myprogdroptarget so that this icon becomes a "magic" drop target for objects. 注册.myprogdroptarget的drop handler,以便此图标成为对象的“神奇”放置目标。

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 有关如何在ATL / C ++中创建Drop Handler的示例代码,请查看Microsoft All-In-One代码框架 ,特别是类ATLShellExtDragAndDropHandler.cpp

Alternate solution: 替代解决方案:

Consider creating a Windows Desktop Gadget that performs similar functionality. 考虑创建一个执行类似功能的Windows桌面小工具。 The coding should be simpler since you won't have to dig into C++. 编码应该更简单,因为您不必深入研究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. 曾经有一个名为魔术文件夹的Vista小工具接受了作为放置目标的项目,但我无法再在Windows库中找到它。 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://www.howtogeek.com/howto/windows-vista/keep-your-vista-desktop-clean-with-the-magic-folder/

And here is a link to the author (maybe he'll share the source code if you ask nicely): http://davecra.wordpress.com/ 这里有一个链接到作者(如果你问得很好,也许他会分享源代码): http//davecra.wordpress.com/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM