vb.net 关于文件拖拽 获得路径有关问题,

vb.net 关于文件拖拽 获得路径问题,高手请进!!!
问题1:有何方法实现上述功能,功能描述,Form里拖一TextBox, 从桌面或者其他盘符拖拽文件到TextBox里,显示文件路径?
问题2:
  网上搜到的代码,可是找不到获取路径的方法!(拖拽已实现..) 文件拖拽可以通过控件的drag属性进行设置,然后响应它的drag事件进行,但是有些控件并不支持文件拖拽

有鉴于此,本文中写的是一个实现任意窗体、控件、组件响应文件拖拽的类,用法也很简单

以Form为例,首先定义一个全局变量

Private pDrag As DragDropFiles

然后在form的load事件中


pDrag.DragDropHwnd = Me.Handle
pDrag.DragDropLoad()

此时就可以向form中拖入文件

pDrag.DragDropFiles即为拖入文件的文件路径集合,可以对拖入文件进行操作了

在Form的close事件中

pDrag.DragDropUnLoad()

 

类源代码如下:

Imports System.Runtime.InteropServices

''' 
''' 本例是采用子类派生技术实现的文件从EXPLORE到VB程序的拖放 通过三个API函数DragAcceptFiles、DragQueryFiles和DragFinish并通过回调函数WindowProc,窗口属性函数SetWindowLong、CallWindowProc的使用实现。
''' 
''' 
Public Class DragDropFiles

#Region "与外部交互"
  Private m_DragDropFiles As New List(Of String)
  ''' 
  ''' 托拽的文件路径list
  ''' 
  ''' 
  ''' 
  ''' 
  ReadOnly Property DragDropFiles() As List(Of String)
  Get
  Return m_DragDropFiles
  End Get
  End Property
  Private m_Hwnd As Integer
  ''' 
  ''' 当前需要接受文件拖动的控件的句柄
  ''' 
  ''' 
  ''' 
  WriteOnly Property DragDropHwnd() As Integer
  Set(ByVal value As Integer)
  m_Hwnd = value
  End Set
  End Property
  ''' 
  ''' 加载Dragdrop
  ''' 
  ''' 
  Overridable Sub DragDropLoad()
  '定义 frmDragDropFiles窗体作为接收文件拖放的容器
  'DragAcceptFiles Me.hwnd, 1&
  DragAcceptFiles(m_Hwnd, 1&)
  '整个procOld变量用来存储窗口的原始参数,以便恢复
  ' 调用了 SetWindowLong 函数,它使用了 GWL_WNDPROC 索引来创建窗口类的子类,通过这样设置
  '操作系统发给窗体的消息将由回调函数 (WindowProc) 来截取, AddressOf是关键字取得函数地址
  Dim mysub As New DelegateWindowProc(AddressOf WindowProc)
  GCHandle.Alloc(mysub) ''为委托建立句柄,以免它被垃圾回收,导致出错
  '第二种避免垃圾回收的办法
  'GC.Collect()
  'GC.WaitForPendingFinalizers()
  'GC.Collect()
  procOld = SetWindowLong(m_Hwnd, GWL_WNDPROC, mysub)
  'procOld = SetWindowLong(m_Hwnd, GWL_WNDPROC, AddressOf WindowProc)
  'AddressOf是一元运算符,它在过程地址传送到 API 过程之前,先得到该过程的地址
  End Sub
  ''' 
  ''' 卸载dragdrop
  ''' 
  ''' 
  Sub DragDropUnLoad()
  '此句关键,把窗口(不是窗体,而是具有句柄的任一控件,这里指Picture1)的属性复原
  SetWindowLong(m_Hwnd, GWL_WNDPROC, procOld)
  End Sub
  ''' 
  ''' 解析字符串,将全路径解析获得路径和文件名
  ''' 
  ''' 全路径
  ''' 路径
  ''' 文件名
  ''' 
  Sub DragDropStringParse(ByVal pFilePath As String, ByRef pPath As String, ByRef pName As String)
  Dim i As Integer = pFilePath.LastIndexOf("\")
  pPath = pFilePath.Substring(0, i)
  pName = pFilePath.Substring(i + 1)
  End Sub
#End Region

#Region "拖放操作相关的API函数"
  Private Const MAX_PATH As Long = 260&
  '标示我们要截获的消息
  Private Const WM_DROPFILES As Long = &H233&
  '保存原 窗体属性的变量,其实是默认的 窗体函数 的地址
  Private procOld As Integer
  Private Const GWL_WNDPROC As Long = (-4&)
  Private Declare Function CallWindowProc Lib "user32.dll" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Integer, ByVal hwnd As Integer, ByVal Msg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
  Private Declare Sub DragAcceptFiles Lib "shell32.dll" (ByVal hWnd As Int32, ByVal fAccept As Int32)