附件:http://files.cnblogs.com/xe2011/CSharp_DragQueryFile.rar

DragQueryFile-LMLPHP

using System.Runtime.InteropServices;
  this.AllowDrop = true;
        [DllImport("shell32.dll")]
public static extern uint DragQueryFile(int hDrop, uint iFile, StringBuilder lpszFile, uint cch);
[DllImport("shell32.dll")]
private static extern void DragAcceptFiles(IntPtr hWnd, bool fAccept); [DllImport("shell32.dll")]
private static extern void DragFinish(int hDrop); const int WM_DROPFILES = 0x0233;
 protected override void WndProc(ref Message Msg)
{
if (Msg.Msg == WM_DROPFILES)
{
uint FilesCount = DragQueryFile((int)Msg.WParam, 0xFFFFFFFF, null, );
richTextBox1.Clear();
StringBuilder FileName = new StringBuilder();
for (uint i = ; i < FilesCount; i++)
{
DragQueryFile((int)Msg.WParam, i, FileName, );
richTextBox1.AppendText(FileName.ToString() + "\r\n");
}
DragFinish((int)Msg.WParam);
return;
}
base.WndProc(ref Msg);
}
        private void Form1_Load(object sender, EventArgs e)
{
DragAcceptFiles(this.Handle, true);
}
04-22 15:40