How to get the name of the application that generated the drag and drop

How do I know which application has omitted some content in my C # form?

Now I am making some wild guesses, for example

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

But I'm really looking for something like:

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

How can i do this?

+3
source share
2 answers

Well, this is what I ended up doing for those who are interested ...

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

As far as I know, there is no direct information in the drag and drop structure indicating the original application.

See * Clipboard Shell Formats (MSDN).

, , Internet Explorer, CFSTR_UNTRUSTEDDRAGDROP ; AFAIK, Internet Explorer - .

+1

Source: https://habr.com/ru/post/1713154/


All Articles