WIN-API方法向表单拖放文件,文件路径及名称显示到列表框中
2008-12-09 15:29
393 查看
出处:http://www.news2news.com/vfp/?function=-1&example=323
环境支持:VFP9.0
从Windows拖拽文件到表单,文件路径及名称将自动添加到列表框中
Local oForm As TForm
oForm=Createobject("TForm")
oForm.Visible=.T.
Read Events
* end of main
Define Class TForm As Form
#Define WM_DROPFILES 0x0233
#Define GWL_WNDPROC -4
#Define MAX_PATH 260
Protected hWindow,hOrigProc
hWindow=0
hOrigProc=0
Width=500
Height=200
MinButton=.F.
MaxButton=.F.
Caption="向表单拖放文件 (环境支持:VFP9.0)" &&Dropping files on the form
ShowWindow=2
AutoCenter=.T.
Add Object ch As Checkbox With Left=10,Top=10,AutoSize=.T.,BackStyle=0,Caption="允许拖放文件",Value=0 &&Accept dropped files
Add Object lst As ListBox With Left=5,Top=40,Width=490,Height=130
* Drag files from an Explorer window and drop on the listbox
Add Object lbl As Label With Left=10,Top=176,AutoSize=.T.,BackStyle=0,Caption="从Windows拖拽文件到表单,文件路径及名称将自动添加到列表框中."
Procedure Init
This.Declare
Endproc
Procedure Destroy
This.ReleaseAccept
Clear Events
Endproc
Procedure ch.InteractiveChange
If This.Value=1
Thisform.SetAccept
Else
Thisform.ReleaseAccept
Endif
Endproc
Procedure SetAccept
This.hWindow=GetFocus()
This.hOrigProc=GetWindowLong(This.hWindow,GWL_WNDPROC)
If Version(5)>=900
=Bindevent(This.hWindow,WM_DROPFILES,This,"OnFilesDropped")
Endif
=DragAcceptFiles(This.hWindow,1)
Endproc
Procedure ReleaseAccept
=Unbindevents(This)
If This.hWindow<>0
=DragAcceptFiles(This.hWindow,0)
This.hWindow=0
Endif
Endproc
Procedure OnFilesDropped(hWindow As Integer,nMsgID As Integer,wParam As Integer,Lparam As Integer)
* requires VFP9,otherwise ignored
* note that input parameters are predefined and should not be changed
* see WindowProc function for details
Local nReturn
nReturn=0
Do Case
Case nMsgID=WM_DROPFILES
This.ProcessDroppedFiles(wParam)
Otherwise
* pass control to the original window procedure
nReturn=CallWindowProc(This.hOrigProc,This.hWindow,m.nMsgID,m.wParam,m.lParam)
Endcase
Return nReturn
Endproc
Protected Procedure ProcessDroppedFiles(hDrop)
Local cPoint,nX,nY
cPoint=Replicate(Chr(0),8) && POINT buffer
=DragQueryPoint(hDrop,@cPoint)
nX=buf2dword(Substr(cPoint,1,4))
nY=buf2dword(Substr(cPoint,5,4))
* Only If clicked inside the ListBox
With This.lst
If Not (Between(nX,.Left,.Left+.Width-1) And Between(nY,.Top,.Top+.Height-1))
Return
=DragFinish(hDrop)
Endif
Endwith
This.lst.Clear
Local nFilecount,nIndex,cBuffer,nLength
nFilecount=DragQueryFile(hDrop,0xFFFFFFFF,Null,0)
For nIndex=0 To nFilecount-1
cBuffer=Replicate(Chr(0),MAX_PATH)
nLength=DragQueryFile(hDrop,nIndex,@cBuffer,MAX_PATH)
cBuffer=Substr(cBuffer,1,nLength)
This.lst.AddItem(cBuffer)
Next
=DragFinish(hDrop)
Endproc
Protected Procedure Declare
Declare Integer GetFocus In user32
Declare DragFinish In shell32 Integer hDrop
Declare DragAcceptFiles In Shell32 Integer hWindow,Integer fAccept
Declare Integer DragQueryFile In shell32 Integer hDrop,Integer iFile,String @lpszFile,Integer cch
Declare Integer DragQueryPoint In shell32 Integer hDrop,String @lppt
Declare Integer CallWindowProc In user32 Integer lpPrevWndFunc,Integer hWindow,Long Msg,Integer wParam,Integer Lparam
Declare Integer GetWindowLong In user32 Integer hWindow,Integer nIndex
Endproc
Enddefine
Function buf2dword(lcBuffer)
Return Asc(Substr(lcBuffer,1,1))+Bitlshift(Asc(Substr(lcBuffer,2,1)), 8)+Bitlshift(Asc(Substr(lcBuffer,3,1)),16)+Bitlshift(Asc(Substr(lcBuffer,4,1)),24)
Endfunc
环境支持:VFP9.0
从Windows拖拽文件到表单,文件路径及名称将自动添加到列表框中
Local oForm As TForm
oForm=Createobject("TForm")
oForm.Visible=.T.
Read Events
* end of main
Define Class TForm As Form
#Define WM_DROPFILES 0x0233
#Define GWL_WNDPROC -4
#Define MAX_PATH 260
Protected hWindow,hOrigProc
hWindow=0
hOrigProc=0
Width=500
Height=200
MinButton=.F.
MaxButton=.F.
Caption="向表单拖放文件 (环境支持:VFP9.0)" &&Dropping files on the form
ShowWindow=2
AutoCenter=.T.
Add Object ch As Checkbox With Left=10,Top=10,AutoSize=.T.,BackStyle=0,Caption="允许拖放文件",Value=0 &&Accept dropped files
Add Object lst As ListBox With Left=5,Top=40,Width=490,Height=130
* Drag files from an Explorer window and drop on the listbox
Add Object lbl As Label With Left=10,Top=176,AutoSize=.T.,BackStyle=0,Caption="从Windows拖拽文件到表单,文件路径及名称将自动添加到列表框中."
Procedure Init
This.Declare
Endproc
Procedure Destroy
This.ReleaseAccept
Clear Events
Endproc
Procedure ch.InteractiveChange
If This.Value=1
Thisform.SetAccept
Else
Thisform.ReleaseAccept
Endif
Endproc
Procedure SetAccept
This.hWindow=GetFocus()
This.hOrigProc=GetWindowLong(This.hWindow,GWL_WNDPROC)
If Version(5)>=900
=Bindevent(This.hWindow,WM_DROPFILES,This,"OnFilesDropped")
Endif
=DragAcceptFiles(This.hWindow,1)
Endproc
Procedure ReleaseAccept
=Unbindevents(This)
If This.hWindow<>0
=DragAcceptFiles(This.hWindow,0)
This.hWindow=0
Endif
Endproc
Procedure OnFilesDropped(hWindow As Integer,nMsgID As Integer,wParam As Integer,Lparam As Integer)
* requires VFP9,otherwise ignored
* note that input parameters are predefined and should not be changed
* see WindowProc function for details
Local nReturn
nReturn=0
Do Case
Case nMsgID=WM_DROPFILES
This.ProcessDroppedFiles(wParam)
Otherwise
* pass control to the original window procedure
nReturn=CallWindowProc(This.hOrigProc,This.hWindow,m.nMsgID,m.wParam,m.lParam)
Endcase
Return nReturn
Endproc
Protected Procedure ProcessDroppedFiles(hDrop)
Local cPoint,nX,nY
cPoint=Replicate(Chr(0),8) && POINT buffer
=DragQueryPoint(hDrop,@cPoint)
nX=buf2dword(Substr(cPoint,1,4))
nY=buf2dword(Substr(cPoint,5,4))
* Only If clicked inside the ListBox
With This.lst
If Not (Between(nX,.Left,.Left+.Width-1) And Between(nY,.Top,.Top+.Height-1))
Return
=DragFinish(hDrop)
Endif
Endwith
This.lst.Clear
Local nFilecount,nIndex,cBuffer,nLength
nFilecount=DragQueryFile(hDrop,0xFFFFFFFF,Null,0)
For nIndex=0 To nFilecount-1
cBuffer=Replicate(Chr(0),MAX_PATH)
nLength=DragQueryFile(hDrop,nIndex,@cBuffer,MAX_PATH)
cBuffer=Substr(cBuffer,1,nLength)
This.lst.AddItem(cBuffer)
Next
=DragFinish(hDrop)
Endproc
Protected Procedure Declare
Declare Integer GetFocus In user32
Declare DragFinish In shell32 Integer hDrop
Declare DragAcceptFiles In Shell32 Integer hWindow,Integer fAccept
Declare Integer DragQueryFile In shell32 Integer hDrop,Integer iFile,String @lpszFile,Integer cch
Declare Integer DragQueryPoint In shell32 Integer hDrop,String @lppt
Declare Integer CallWindowProc In user32 Integer lpPrevWndFunc,Integer hWindow,Long Msg,Integer wParam,Integer Lparam
Declare Integer GetWindowLong In user32 Integer hWindow,Integer nIndex
Endproc
Enddefine
Function buf2dword(lcBuffer)
Return Asc(Substr(lcBuffer,1,1))+Bitlshift(Asc(Substr(lcBuffer,2,1)), 8)+Bitlshift(Asc(Substr(lcBuffer,3,1)),16)+Bitlshift(Asc(Substr(lcBuffer,4,1)),24)
Endfunc
相关文章推荐
- 向表单拖放文件,文件路径及名称显示到列表框中(更简单的方法)
- vi/vim文件打开时显示正在打开文件名称的方法
- Foxpro数据库连接错误解决方法--【VFP DBF文件不是一个有效的路径。 确定路径名称拼写是否正确,以及是否连接到文件存放的服务器】
- 获取bash文件所在的目录绝对路径以及获取函数方法名称
- SourceInsight标题栏显示完整路径文件的方法
- C# 根据包含文件的路径和文件的名称的字符串获取文件名称的几种方法
- web页面表单显示代码类名称的方法介绍
- ubuntu 12.10 显示文件完整路径的方法
- 通过托放文件到TextBox,在其中显示文件名称的方法
- ie6文件下载,文件名称显示为代码路径名(程序部署在linux)
- 上传文件框在firefox浏览器中显示路径不全的解决方法
- C# 根据包含文件的路径和文件的名称的字符串获取文件名称的几种方法
- 在vc中用MFC按纽打开一个txt文件,在旁边的文本框里显示文件的路径的方法??
- busybox 显示用户名及路径 -----[\u@\h\W]\# busybox 在制作根文件系统的处理方法
- wtl 支持托拽文件并在ListBox框中显示文件路径的方法
- 在vc中用MFC按纽打开一个txt文件,在旁边的文本框里显示文件的路径的方法
- win显示隐藏文件的方法
- 在数据库中 存储图片 以及 在界面中显示图片(存储图片路径)- 这种方法相对与存储二进制文件好
- windows系统中显示文件的后缀名称方法
- 让Win8文件资源管理器显示全路径的设置方法