DragQueryFile

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

 

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, 0);
                richTextBox1.Clear();
                StringBuilder FileName = new StringBuilder(1024);
                for (uint i = 0; i < FilesCount; i++)
                {
                    DragQueryFile((int)Msg.WParam, i, FileName, 1024);
                    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);
        }

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

posted @ 2013-12-03 20:33  XE2011  阅读(754)  评论(0编辑  收藏  举报