2009-07-21 93 views
3

如何找出哪些應用程序在我的C#表單上放置了一些內容?如何獲取生成拖放的應用程序的名稱

現在,我做了一些亂撞,像

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

。但我真正需要的是這樣的:

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

我怎樣才能做到這一點?

+0

好問題,也是,如果有人知道這個相反的(如何獲得拖動項目的放置位置從創建的應用程序),他們也可以分享:-) – ThePower 2009-07-21 14:43:06

+1

對於反之亦然的情況,我想你可能只是檢測用戶放開鼠標的位置,然後使用窗口句柄到PID邏輯找出它。這有點破解,但這是一個更容易的問題。 – EricLaw 2009-07-21 14:47:21

回答

-1

OK,這是我落得這樣做,對於那些有興趣...

// 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

據我所知,在拖放結構中沒有直接的信息表明原始應用程序。

請參閱* Shell Clipboard Formats(MSDN)。

如果您只是想了解它是否是因特網 資源管理器的丟失,那麼CFSTR_UNTRUSTEDDRAGDROP的出現是一個線索; AFAIK,只有互聯網 資源管理器和Web瀏覽器控件將把這種格式放在剪貼板上。

相關問題