VB 拖动操作

来源:百度知道 编辑:UC知道 时间:2024/05/21 17:00:20
请高手指点拖动操作的代码该如何写。
比如,怎样实现如下的效果:
程序中有一个文本框,一个ListView对象。
将桌面上的某文件拖动到ListView上面后,
文本框显示出文件的名称
两位高手的答案我无法理解,也不好试验。
请给出详细的思路,或是直接给出可以运行的有针对性的代码,
太长的代码,又没有思路,我无法理解啊,帮帮忙!!
如果问题得到解决,我会再追加50分

建立工程。建立窗体文件和一个模块,把代码分别放在上面,然后再窗体上添加控件 ,你就可以试验了。

代码是往Picture1控件上加拖拽,自己修改一下控件吧!

1、建立vb工程

窗体代码如下
Option Explicit

‘api用到的参数
Private Const GWL_WNDPROC As Long = (-4&)

' API call to alter the class data for this window
Private Declare Function SetWindowLong& Lib "user32" Alias "SetWindowLongA" (ByVal hWnd&, _
ByVal nIndex&, ByVal dwNewLong&)

’窗体load事件
Private Sub Form_Load()

' register picture1 as a window that accepts dragdrop files

’获得控件的句柄。
DragAcceptFiles Picture1.hWnd, 1&

' take control of message processing by installing our message handling
' routine into the chain of message routines for picture1
procOld = SetWindowLong(Picture1.hWnd, GWL_WNDPROC, AddressOf WindowProc)

End Sub