社区应用 最新帖子 精华区 社区服务 会员列表 统计排行 社区论坛任务 迷你宠物
  • 3205阅读
  • 3回复

又有点小收获了..VB拖放操作

级别: 经院高中
发帖
369
铜板
3800
人品值
215
贡献值
0
交易币
0
好评度
305
信誉值
0
金币
0
所在楼道
还是很简单的.为了我的软件写的更完美先 in#lpDa[  
ZXC_kmBN/  
抄别人的..嘎嘎~~~~ MWJ}  
抓图如下拉: e^yfoE<7  
b&2 N7%  
_Z_R\  
FORM代码如下: j kV9$W0  
  1. Option Explicit
  2. ' A demo project of DragDrop file routines. This demo shows the difference
  3. ' between using a subclassed dragdrop routine and an OLE dragdrop routine.
  4. ' written by Bryan Stafford of New Vision Software?
  5. ' this demo is released into the public domain "as is" without
  6. ' warranty or guaranty of any kind. In other words, use at
  7. ' your own risk.
  8. Private Const GWL_WNDPROC As Long = (-4&)
  9.  
  10. ' API call to alter the class data for this window
  11. Private Declare Function SetWindowLong& Lib "user32" Alias "SetWindowLongA" (ByVal hWnd&, _
  12.                                         ByVal nIndex&, ByVal dwNewLong&)
  13. Private Sub Form_Load()
  14. ' register picture1 as a window that accepts dragdrop files
  15. DragAcceptFiles qqq.hWnd, 1&
  16. ' take control of message processing by installing our message handling
  17. ' routine into the chain of message routines for picture1
  18. procOld = SetWindowLong(qqq.hWnd, GWL_WNDPROC, AddressOf WindowProc)
  19.                  
  20. End Sub
  21. Private Sub Form_Unload(Cancel As Integer)
  22. ' give message processing control back to VB
  23. ' if you don't do this you WILL crash!!!
  24. Call SetWindowLong(qqq.hWnd, GWL_WNDPROC, procOld)
  25. End Sub
  26. Public Sub DropFiles(ByVal hDrop&)
  27. Dim sFileName$, nCharsCopied&
  28. ' make some space for the file name
  29. sFileName = String$(MAX_PATH, vbNullChar)
  30. ' pass the file handle (hDrop), the index of the file if more than 1 was passed (we
  31. ' still use index zero since we only care about the first file in the list), the variable
  32. ' that will accept the file name and the amount of space that that variable is dimentioned for.
  33. nCharsCopied = DragQueryFile(hDrop, 0&, sFileName, MAX_PATH)
  34. ' clean up after ourselves bu closing the file handle
  35. DragFinish hDrop
  36. ' if there were chars copied, get the file name and try to load it into the picturbox
  37. If nCharsCopied Then
  38.   sFileName = Left$(sFileName, nCharsCopied)
  39.   ' incase it's not a valid picture display the error message
  40.   qqq.Text = sFileName
  41. End If
  42. Exit Sub
  43. End Sub
nUf0TkA  
>Q[3t79^  
  1. Option Explicit
  2. ' A demo project of DragDrop file routines. This demo shows the difference
  3. ' between using a subclassed dragdrop routine and an OLE dragdrop routine.
  4. ' written by Bryan Stafford of New Vision Software?
  5. ' this demo is released into the public domain "as is" without
  6. ' warranty or guaranty of any kind. In other words, use at
  7. ' your own risk.
  8. ' See the comments at the end of this module for a brief explaination of
  9. ' what subclassing is.
  10. ' max length of a path string on the system
  11. Public Const MAX_PATH As Long = 260&
  12. ' the messages that we want to catch
  13. Public Const WM_DROPFILES As Long = &H233&
  14. ' this var will hold a pointer to the original message handler so we MUST
  15. ' save it so that it can be restored before we exit the app. if we don't
  16. ' restore it.... CRASH!!!!
  17. Public procOld As Long
  18. '
  19. Public Declare Function CallWindowProc& Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc&, _
  20.                                   ByVal hWnd&, ByVal Msg&, ByVal wParam&, ByVal lParam&)
  21.                                  
  22. ' drag and drop files APIs
  23. Public Declare Sub DragAcceptFiles Lib "shell32.dll" (ByVal hWnd&, ByVal fAccept&)
  24.                    
  25. Public Declare Function DragQueryFile& Lib "shell32.dll" Alias "DragQueryFileA" (ByVal hDrop&, ByVal iFile&, _
  26.                                                       ByVal lpszFile$, ByVal cch&)
  27. Public Declare Sub DragFinish Lib "shell32.dll" (ByVal hDrop&)
  28. 'WARNING!!!! WARNING!!!! WARNING!!!! WARNING!!!! WARNING!!!! WARNING!!!!
  29. '
  30. ' Do NOT try to step through this function in debug mode!!!!
  31. ' You WILL crash!!! Also, do NOT set any break points in this function!!!
  32. ' You WILL crash!!! Subclassing is non-trivial and should be handled with
  33. ' EXTREAME care!!!
  34. '
  35. ' There are ways to use a "Debug" dll to allow you to set breakpoints in
  36. ' subclassed code in the IDE but this was not implimented for this demo.
  37. '
  38. 'WARNING!!!! WARNING!!!! WARNING!!!! WARNING!!!! WARNING!!!! WARNING!!!!
  39. Public Function WindowProc(ByVal hWnd As Long, ByVal iMsg As Long, _
  40.                               ByVal wParam As Long, ByVal lParam As Long) As Long
  41.  
  42. ' this is *our* implimentation of the message handling routine
  43. ' determine which message was recieved
  44. Select Case iMsg
  45.  
  46.   ' grab the message that tells us when a file was dropped on the picturebox
  47.   Case WM_DROPFILES
  48.     ' call the sup that we defined in the form module passing wParam which is the handle to the file
  49.     frmDragDropFiles.DropFiles wParam
  50.    
  51.     ' return zero to windows and get out
  52.     WindowProc = False
  53.     Exit Function
  54.    
  55. End Select
  56. ' pass all messages on to VB and then return the value to windows
  57. WindowProc = CallWindowProc(procOld, hWnd, iMsg, wParam, lParam)
  58. End Function
  59. ' What is subclassing anyway?
  60. '
  61. ' Windows runs on "messages". A message is a unique value that, when
  62. ' recieved by a window or the operating system, tells either that
  63. ' something has happened and that an action of some sort needs to be
  64. ' taken. Sort of like your nervous system passing feeling messages
  65. ' to your brain and the brain passing movement messages to your body.
  66. '
  67. ' So, each window has what's called a message handler. This is a
  68. ' function where all of the messages FROM Windows are recieved. Every
  69. ' window has one. I mean EVERY window. That means every button, textbox,
  70. ' picturebox, form, etc... Windows keeps track of where the message
  71. ' handler (called a WindowProc [short for PROCedure]) in a "Class"
  72. ' structure associated with each window handle (otherwise known as hWnd).
  73. '
  74. ' What happens when a window is subclassed is that you insert a new
  75. ' window procedure in line with the original window procedure. In other
  76. ' words, Windows sends the messages for the given window to YOUR WindowProc
  77. ' FIRST where you are responsible for handling any messages you want to
  78. ' handle. Then you MUST pass the remaining messages on to the default
  79. ' WindoProc. So it looks like this:
  80. '
  81. ' Windows Message Sender --> Your WindowProc --> Default WindowProc
  82. '
  83. ' A window can be subclassed MANY times so it could look like this:
  84. '
  85. ' Windows Message Sender --> Your WindowProc --> Another WindowProc _
  86. ' --> Yet Another WindowProc --> Default WindowProc
  87. '
  88. ' You can also change the order of when you respond to a message by
  89. ' where in your routine you pass the message on to the default WindowProc.
  90. ' Let's say that you want to draw something on the window AFTER the
  91. ' default WindowProc handles the WM_PAINT message. This is easily done
  92. ' by calling the default proc before you do your drawing.   Like so:
  93. '
  94. ' Public Function WindowProc(Byval hWnd, Byval etc....)
  95. '
  96. '   Select Case iMsg
  97. '   Case SOME_MESSAGE
  98. '     DoSomeStuff
  99. '
  100. '   Case WM_PAINT
  101. '     ' pass the message to the defproc FIRST
  102. '     WindowProc = CallWindowProc(procOld, hWnd, iMsg, wParam, lParam)
  103. '
  104. '     DoDrawingStuff ' <- do your drawing
  105. '
  106. '     Exit Function ' <- exit since we already passed the
  107. '               '   measage to the defproc
  108. '
  109. '   End Select
  110. '
  111. '   ' pass all messages on to VB and then return the value to windows
  112. '   WindowProc = CallWindowProc(procOld, hWnd, iMsg, wParam, lParam)
  113. '
  114. ' End Function
  115. '
  116. '
  117. ' This is just a basic overview of subclassing but I hope it helps if
  118. ' you were fuzzy about the subject before reading this.
  119. '
H_>9'(  
|}isSCt  
注释倒是挺多滴!!呵呵....开心哦...
评价一下你浏览此帖子的感受

精彩

感动

搞笑

开心

愤怒

无聊

灌水
级别: 经院博士
发帖
3975
铜板
4727
人品值
1147
贡献值
565
交易币
0
好评度
3833
信誉值
0
金币
0
所在楼道
学一楼
只看该作者 1 发表于: 2006-06-12
深奥 ]\ t20R{z  
z>z9xG'  
这个是干傻用的?
引用

引用
想找我?如果我即不在 石家庄经济学院论坛www.uebbs.net,也不在宿舍,那,我肯定是在去的路上

引用
级别: 经院高中
发帖
369
铜板
3800
人品值
215
贡献值
0
交易币
0
好评度
305
信誉值
0
金币
0
所在楼道
只看该作者 2 发表于: 2006-06-12
就是拖放用的嘛。。。。 u4h.\ul8%  
lQ&J2H<w  
把一个文件拖进去,然后就能显示文件的路径啊。。 QXEz  
~rlPS#]o  
别的没有了。
级别: 终身会员
发帖
3743
铜板
8
人品值
493
贡献值
9
交易币
0
好评度
3746
信誉值
0
金币
0
所在楼道
只看该作者 3 发表于: 2006-06-12
学习~~~ v^aI+p6  
看代码不是要问他干吗用 -?w3j9kk>  
是用来学习的 |f1RhB  
只有多看看代码才能编出好的代码~ i?861Hu  
就是不懂VB Ffig0K+ `  
还是顶一下~
描述
快速回复

您目前还是游客,请 登录注册
欢迎提供真实交流,考虑发帖者的感受
认证码:
验证问题:
3+5=?,请输入中文答案:八 正确答案:八