侯捷先生的《深入浅出mfc》写的好,可惜是繁体的。
解决方案 »
- 关于合并两个表的问题向各位高手请教???
- 请问各位大哥,如何用代码注册.DLL和.ocx
- 在VB中如何执行openxml的查询方式
- 我用VB控制WORD的时候!出现"OLE自动化错误"!!!可是同一个程序拷到别台机子上却没问题!
- 如何禁止对 Maskedbox 控件内容的删除和插入?
- 请问:ADO+Access 多表查询问题!
- 一个很简单的SQL问题,在线等,急
- 各位朋友,我的主页上完工了,谢谢。请问大家知道国内有没有20MB以上免费的空间?
- 在记事本可以截取到内容!但如何截取word中的内容?(附源程序)
- 请问有没有哪位大侠用过TideStone
- 关于在vb中如何用代码实现在mapinfo图层上画点,线,区域
- MSFlexGrid 中的保存问题,各位高手请帮帮忙,谢谢
'************************************************************
'一个从explorer中拖放文件的例子
'功能是从explorer中拖文件到窗体中并在listbox中显示出文件名
'************************************************************
Option Explicit
Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nindex As Long, ByVal dwnewlong As Long) As Long
Public iprevwndproc As Long
Public hhookwindow As Long
Public Declare Function DragQueryFile Lib "shell32.dll" Alias "DragQueryFileA" (ByVal HDROP As Long, ByVal UINT As Long, ByVal lpStr As String, ByVal ch As Long) As LongPublic Const GWL_WNDPROC = -4
Public Const WM_DROPFILES = &H233
Public Declare Sub DragAcceptFiles Lib "shell32.dll" (ByVal hWnd As Long, ByVal fAccept As Long)
Public Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hWnd As Long, ByVal Msg As Long, ByVal wparam As Long, ByVal lParam As Long) As Long
Public Declare Sub DragFinish Lib "shell32.dll" (ByVal HDROP As Long)
Public Sub SETHOOK(IHWND As Long)
'******************************************************************
'设置挂钩
’*****************************************************************
'be sure the code is not already subclassing
If hhookwindow <> 0 Then Call clearhook
'save the handle of the calling window
hhookwindow = IHWND
'set the subclassing window message hook
iprevwndproc = SetWindowLong(hhookwindow, GWL_WNDPROC, AddressOf hookcallback)
End SubPublic Sub clearhook()
'******************************************************************
'清除挂钩
'******************************************************************
Dim ireturn As Long
'check to be sure that there is a hook active
If hhookwindow = 0 Then Exit Sub
If IsEmpty(hhookwindow) = True Then Exit Sub
If IsNull(hhookwindow) = True Then Exit Sub
'remove the hook fromm the system
ireturn = SetWindowLong(hhookwindow, GWL_WNDPROC, iprevwndproc)
End SubPublic Function hookcallback(ByVal hWnd As Long, ByVal imsg As Long, ByVal wparam As Long, ByVal iparam As Long) As Long
'******************************************************************
'这是一个回调函数,让窗体接受拖放消息。参数个数,及值如何被传来,我不清‘楚,望指点!
'******************************************************************
Select Case hWnd
Case hhookwindow
frmmain.messageproc imsg, wparam, iparam
Case Else
End Select
hookcallback = CallWindowProc(ByVal iprevwndproc, ByVal hWnd, ByVal imsg, ByVal wparam, ByVal iparam)
End Function'窗体中
Option Explicit
Private Sub cmdaction_Click(Index As Integer)
Select Case Index
Case 0
lstfiles.Clear
Case 1
Unload frmmain
End Select
End Sub
Private Sub Form_Load()
Call SETHOOK(Me.hWnd)
Call DragAcceptFiles(Me.hWnd, True)
End SubPrivate Sub Form_Terminate()
Call clearhook
End SubPublic Sub messageproc(imsg As Long, wparam As Long, iparam As Long)
'******************************************************************
'处理拖放消息
'******************************************************************
Dim ndropcount As Long
Dim nloopctr As Integer
Dim ireturn As Long
Dim sfilename As String
Dim HDROP As Long
Select Case imsg
Case WM_DROPFILES
HDROP = wparam
sfilename = Space$(255)
ndropcount = DragQueryFile(HDROP, -1, sfilename, 254)
For nloopctr = 0 To ndropcount - 1
sfilename = Space$(255)
ireturn = DragQueryFile(HDROP, nloopctr, sfilename, 254)
lstfiles.AddItem sfilename
'frmmain.lstfiles.AddItem Left$(sfilename, ireturn)
Next nloopctr
'release the drop structure from memory
Call DragFinish(HDROP)
End Select
End Sub