C# 如何获取生成拖放操作的应用程序的名称

C# 如何获取生成拖放操作的应用程序的名称,c#,drag-and-drop,C#,Drag And Drop,我如何找出哪个应用程序在我的C#表单上删除了一些内容 现在我在做一些疯狂的猜测,比如 if (e.Data.GetDataPresent("UniformResourceLocatorW", true)) { // URL dropped from IExplorer } 但我真正想要的是: if (isDroppedFrom("iexplorer")) { // URL dropped from IExplorer } 如何才能做到这一点?据我所知,拖放结构中没有指示原始应用程序的

我如何找出哪个应用程序在我的C#表单上删除了一些内容

现在我在做一些疯狂的猜测,比如

if (e.Data.GetDataPresent("UniformResourceLocatorW", true)) {
  // URL dropped from IExplorer
}
但我真正想要的是:

if (isDroppedFrom("iexplorer")) {
  // URL dropped from IExplorer
}

如何才能做到这一点?

据我所知,拖放结构中没有指示原始应用程序的直接信息

见*(MSDN)


如果你只想知道这是不是InternetExplorer的一次下载,那么CFSTR_UNTRUSTEDDRAGDROP的出现就是一个线索;好的,只有InternetExplorer和Web浏览器控件会将此格式放在剪贴板上。

好的,这就是我最后要做的,对那些感兴趣的人来说

// Firefox //
if (e.Data.GetDataPresent("text/x-moz-url", true)) {
    HandleFirefoxUrl(e);
} else if (e.Data.GetDataPresent("text/_moz_htmlcontext", true)) {
    HandleFirefoxSnippet(e);

// Internet Explorer //
} else if (e.Data.GetDataPresent("UntrustedDragDrop", false)) {
    HandleIELink(e);
} else if (e.Data.GetDataPresent("UniformResourceLocatorW", false)) {
    HandleIEPage(e);

} else if (e.Data.GetDataPresent(DataFormats.FileDrop, true)) { //FILES
    Array droppedFiles = (Array)e.Data.GetData(DataFormats.FileDrop);
    HandleFiles(droppedFiles);

} else if (e.Data.GetDataPresent(DataFormats.Bitmap, true)) { // BITMAP
    Bitmap image = (Bitmap)Clipboard.GetDataObject().GetData(DataFormats.Bitmap);
    HandleBitmap(image);

} else if (e.Data.GetDataPresent(DataFormats.Html, true)) { // HTML
    String pastedHtml = (string)e.Data.GetData(DataFormats.Html);
    HandleHtml(pastedHtml);

} else if (e.Data.GetDataPresent(DataFormats.CommaSeparatedValue, true)) { // CSV
    MemoryStream memstr = (MemoryStream)e.Data.GetData("Csv");
    StreamReader streamreader = new StreamReader(memstr);
    String pastedCSV = streamreader.ReadToEnd();
    HandleCSV(pastedCSV);

    //  } else if (e.Data.GetDataPresent(DataFormats.Tiff, true)) {
    //  } else if (e.Data.GetDataPresent(DataFormats.WaveAudio, true)) {

} else if (e.Data.GetDataPresent(DataFormats.Text, true)) { //TEXT
    String droppedText = e.Data.GetData(DataFormats.Text).ToString();
    HandleText(droppedText);

[else if .....]

} else { // UNKNOWN
    Debug.WriteLine("unknown dropped format");
}

还有一个好问题,如果有人知道与此相反的情况(如何从创建的应用程序中获取拖动项的放置位置),他们是否也可以共享:-)对于反之亦然的情况,我认为您可能只需检测用户释放鼠标的位置,然后使用窗口句柄到PID逻辑来找出答案。这可能有点麻烦,但这是一个更容易的问题。对于html内容,可以在SourceURL“item”中找到它:String pastedHtml=(String)e.Data.GetData(DataFormats.html);版本:1.0 StartHTML:000000182 EndHTML:000008325 StartFragment:000008144 EndFragment:000008205 StartSelection:000008144 EndSelection:000008205 SourceURL:谢谢Eric,听起来不错。不过,我需要区分所有主要的应用类型(ffox、ie、word、excel、电子邮件等)。所以现在我正在通过嗅探一些提示,比如UniformResourceCatorw之类的,但是我希望找到一种更通用、更可靠的方法。。。