教程中国
PHOTOSHOP CS9.0中文版 MAYA 8.5 FOR WINDOWS Corel Painter v9.0 Flash MX2004 中文版 Illustrator cs2 中文版
VC++6.0含sp6 中英文版 VB6.0 +sp6 简体中文版 Borland Delphi 7汉化版 MSDN for vb6.0中文版 Visual Studio 2005简体
教程中国下属 文件存储共享专家BIBIDU.COM 提供大型软件,教材,源码,电影,音乐,图书等下载 更多精品请点此进入
  您目前所在位置: 教程中国 >> 编程基地 >> VB >> 拖动时显示 ListView 项目 RSS订阅
拖动时显示 ListView 项目
教程(视频,书籍)下载:  ASP.NET AutoCAD 数据库 C# ASP java photoshop 网页设计 delphi 3dmax Flash C++ VB 张孝祥 实例   更多请进入BIBIDU搜索
IT搜索引擎   
拖动时显示 ListView 项目

  这段代码演示了如何利用 ImageList 函数在拖动 ListView 项目的时候显示被拖动的项目图标(就像在资源管理器中所看到的那样)。

Option Explicit

注释: ==== Private members ====
Private m_lIL As Long
Private m_lWndPrev As Long
Private m_lTimer As Long

注释: ==== API declarations ====

Private Declare Function ImageList_BeginDrag Lib "comctl32" ( _
   ByVal himlTrack As Long, _
   ByVal iTrack As Long, _
   ByVal dxHotspot As Long, _
   ByVal dyHotspot As Long) As Long
   
Private Declare Sub ImageList_EndDrag Lib "comctl32" ()

Private Declare Function ImageList_DragEnter Lib "comctl32" ( _
   ByVal hwndLock As Long, _
   ByVal X As Long, _
   ByVal Y As Long) As Long

Private Declare Function ImageList_DragLeave Lib "comctl32" ( _
   ByVal hwndLock As Long) As Long

Private Declare Function ImageList_DragMove Lib "comctl32" ( _
   ByVal X As Long, _
   ByVal Y As Long) As Long

Private Declare Function ImageList_Destroy Lib "comctl32" ( _
   ByVal himl As Long) As Long

Private Type POINTL
   X As Long
   Y As Long
End Type

Private Declare Function GetCursorPos Lib "user32" ( _
   lpPoint As POINTL) As Long
   
Private Declare Function WindowFromPoint Lib "user32" ( _
   ByVal xPoint As Long, _
   ByVal yPoint As Long) As Long

Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" ( _
   ByVal hWnd As Long, _
   ByVal wMsg As Long, _
   ByVal wParam As Long, _
   lParam As Any) As Long

Const LVM_CREATEDRAGIMAGE = &H1000& + 33

Private Type RECT
   Left As Long
   Top As Long
   Right As Long
   Bottom As Long
End Type

Private Declare Function GetWindowRect Lib "user32" ( _
   ByVal hWnd As Long, _
   lpRect As RECT) As Long

Private Declare Function KillTimer Lib "user32" ( _
   ByVal hWnd As Long, _
   ByVal nIDEvent As Long) As Long
   
Private Declare Function SetTimer Lib "user32" ( _
   ByVal hWnd As Long, _
   ByVal nIDEvent As Long, _
   ByVal uElapse As Long, _
   ByVal lpTimerFunc As Long) As Long

注释:
注释: DragComplete
注释:
注释: Removes the drag image
注释:
Public Sub ListViewDragComplete()
   
   注释: Stop the timer
   KillTimer 0, m_lTimer

   注释: End the image dragging
   ImageList_EndDrag
   
   注释: Destroy the ImageList
   ImageList_Destroy m_lIL
   
End Sub

注释:
注释: ListViewStartDrag
注释:
注释: Starts the image dragging
注释:
注释: Parameters:
注释: hWndListView - Window handle of the ListView that
注释:                contains the item to drag
注释: ItemIndex - Index of the item to drag
注释: X, Y - Hot spot coordinates in the image
注释:
Public Sub ListViewStartDrag( _
   ByVal hWndListView As Long, _
   ByVal ItemIndex As Long, _
   Optional ByVal X As Long = 20, _
   Optional ByVal Y As Long = 20)
Dim tPoint As POINTL

   注释: Get a ImageList with
   注释: the drag image
   m_lIL = SendMessage(hWndListView, LVM_CREATEDRAGIMAGE, ItemIndex - 1, tPoint)
   
   注释: Start the image dragging
   ImageList_BeginDrag m_lIL, 0, X, Y
   
   注释: Start the timer
   m_lTimer = SetTimer(0, 0, 1, AddressOf TimerDragMove)

End Sub

Private Sub TimerDragMove( _
   ByVal hWnd As Long, _
   ByVal uMsg As Long, _
   ByVal idEvent As Long, _
   ByVal dwTime As Long)
Dim tPoint As POINTL
Dim tRect As RECT
Dim lWnd As Long
   
   注释: Get the cursor position
   GetCursorPos tPoint
   
   注释: Get the window under
   注释: the cursor
   lWnd = WindowFromPoint(tPoint.X, tPoint.Y)
   
   注释: Check if the cursor has moved
   If lWnd <>  m_lWndPrev Then
   
      注释: Remove the image from
      注释: the previous window
      ImageList_DragLeave m_lWndPrev
      
      注释: Add the image to
      注释: the new window
      ImageList_DragEnter lWnd, 0, 0
      
      注释: Save the current window
      m_lWndPrev = lWnd
      
   End If
   
   注释: Get the window rectangle
   GetWindowRect lWnd, tRect
   
   注释: Convert the screen coordinates
   注释: to window coordinates
   tPoint.X = tPoint.X - tRect.Left
   tPoint.Y = tPoint.Y - tRect.Top
   
   注释: Move the image
   ImageList_DragMove tPoint.X, tPoint.Y
   
End Sub
在 OLEStartDrag 事件代码中调用 ListViewStartDrag:


Private Sub ListView1_OLEStartDrag( _
   Data As ComctlLib.DataObject, _
   AllowedEffects As Long)
   
   ListViewStartDrag ListView1.hWnd, ListView1.SelectedItem.Index

End Sub
同时在 OLECompleteDrag 事件代码中调用 ListViewDragComplete:


Private Sub ListView1_OLECompleteDrag(Effect As Long)
   
   ListViewDragComplete
   
End Sub

来源:upschool.cn
作者:
关键字:拖动时显示,ListView,项目
发表日期:2006-12-20 18:16:32

网页显示有限 阅读全文请下载本文完整版WORD文档

上一篇:用VB制作即时动态按钮   下一篇:OPENFILENAME 新元素初探


2009-1-10 10:35:09
本文的相类似文章
  • TListView在XP中的补丁程序
  • VB 更改LISTVIEW的背景色
  • 项目中的oracle开发技巧
  • 存储过程能不能用在我们的项目中的思考
  • 文档化数据库项目以捕捉相关信息
  • 自由项目实施
  • 添加一个栏目类别到VB的ListView中
  • 用API函数改进ListView控件的显示效果
  • VB中防止将重复项目添加到列表框控件中
  • VB调用API函数技巧--快速选择全部项目
  • 在学习中进步 在进步中成长 教程中国相随您的成长之路
    华腾联合科技股份有限公司版权所有
    广告联系:Rosibo@163.com