代码之家  ›  专栏  ›  技术社区  ›  Renaud

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

  •  3
  • Renaud  · 技术社区  · 16 年前

    如何找出哪个应用程序在我的C#窗体上删除了某些内容?

    if (e.Data.GetDataPresent("UniformResourceLocatorW", true)) {
      // URL dropped from IExplorer
    }
    

    但我真正想要的是:

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

    2 回复  |  直到 10 年前
        1
  •  1
  •   Peter Mortensen Pieter Jan Bonestroo    10 年前

    Shell Clipboard Formats (MSDN)。

    如果你只想知道它是不是从InternetExplorer中下载的,CFSTR_UNTRUSTEDRADROP的存在就是一个线索;AFAIK,只有InternetExplorer和Web浏览器控件会将此格式放在剪贴板上。

        2
  •  -1
  •   Peter Mortensen Pieter Jan Bonestroo    10 年前

    好吧,这就是我最终为那些感兴趣的人所做的。..

    // 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");
    }