ListView_GetItemText 为何不能在DELPHI当中使用?(100分)

  • 主题发起人 主题发起人 ndren
  • 开始时间 开始时间
N

ndren

Unregistered / Unconfirmed
GUEST, unregistred user!
这是一个API函数!可是在DELPHI当中好象不能直接使用?<br>&nbsp; &nbsp; &nbsp;<br>&nbsp; &nbsp; &nbsp;请问这是为何?感谢!
 
kinglaw (2002-6-1 9:54) <br><br>看看delphi带的win32api的帮助吧<br>获取内容可以用 ListView_GetItemText(),它等同于发LVM_GETITEMTEXT消息。<br>The ListView_GetItem macro retrieves the text of a list view item or subitem. You can use this macro or explicitly send the LVM_GETITEMTEXT message.<br>但是还有帮助没说明的就是只能在ListView的同一进程使用,才行的。<br>原因是ListView_GetItemText()是向同一进程的pszText指针写内容的。<br>如直接向另一进程的其中ListView发LVM_GETITEMTEXT消息就会可能出现你上述的错误。<br>因为内容写到ListView进程的的地址上去了。<br>BTW:能够用指针传数据的win32消息,据我所知只有wm_getitem,wm_setitem,wm_copydata等几个<br>,microsoft用特别的技术实现的。<br>那该如何使用LVM_GETITEMTEXT消息获得另一进程的ListView的内容呢?<br>方法就是 windowhook。<br>windowhook能使winhook所在的dll进入另一进程的地址空间,再在该dll中用<br>ListView_GetItemText()获得ListView的内容。<br>&nbsp;<br>
 
兄弟,请看看我的代码:<br>HA 为 SysListView32 的句柄!<br><br>ListView_GetItemText(HA, 1, 2, lptext, 10);<br><br><br>这样的代码在DELPHI不能通过编译!提示好象是 ListView_GetItemText 没有经过定义???这是为何?感谢兄弟!
 
那之前好象是要定义一下的吧,<br>它可能是dll中的一个函数,你要定义一下,怎么定义我不清楚,我还没用过这个函数呐
 
The ListView_GetItem macro retrieves the text of a list view item or subitem. You can use this macro or explicitly send the LVM_GETITEMTEXT message<br>这里说它是个宏,win32的帮助是针对C语言写的,Delphi中哪有宏(Macro)的概念。<br>这个宏估计是通过调用SendMessage之类实现的,将一个消息常数做为参数。<br>Delphi中无法使用它,只能找替代的办法。
 
我使用了<br>&nbsp; SendMessage(SH, LVM_GETITEMCOUNT, 50, Integer(@ServerText));<br>&nbsp; PostMessage(SH, LVM_GETITEMCOUNT, 50, Integer(@ServerText));<br><br>想获取另一个程序当中 ListView 的 Item 的总数!可是系统仍旧提示 LVM_GETITEMCOUNT 未定义!怎么办?大家有好的办法吗?
 
这是VB的一段例子,它都可以正常调用:<br><br>Option Explicit<br>Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long<br>Private Declare Function SendMessageLong Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wmsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long<br>Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long<br>Private Const LVM_GETTITEMCOUNT&amp; = (&amp;H1000 + 4)<br>Private Const LVM_SETITEMPOSITION&amp; = (&amp;H1000 + 15)<br>Private Const LVM_FIRST = &amp;H1000<br>Private Const LVM_GETITEMPOSITION = (LVM_FIRST + 16)<br>Private Const LVM_GETITEMTEXT = LVM_FIRST + 45<br>Private Const LVM_GETIMAGELIST = (LVM_FIRST + 2)<br>Private Const LVSIL_NORMAL = 0<br>Private Const LVM_GETITEM = (LVM_FIRST + 5)<br>Private Const LVM_ARRANGE = (LVM_FIRST + 22)<br>Private Type POINTAPI<br>X As Long<br>y As Long<br>End Type<br>Private Declare Function SystemParametersInfo Lib "user32" Alias "SystemParametersInfoA" (ByVal uAction As Long, ByVal uParam As Long, ByRef lpvParam As Any, ByVal fuWinIni As Long) As Long<br>Private Const SPI_GETWORKAREA = 48<br><br>Public Sub GetDeskIconPosition(ByVal SX As String)<br>'Dim hdesk As Long<br>Dim WorkArea As RECT<br>Dim DeskWidth As Long<br>Dim DeskHeight As Long<br>Dim Pointx() As POINTAPI<br>Dim Hdesk As Long<br>Hdesk = GetrDeskIconHandle()<br>SystemParametersInfo SPI_GETWORKAREA, 0, WorkArea, 0<br>DeskWidth = WorkArea.Right<br>DeskHeight = WorkArea.Bottom<br>Dim IconCount As Long<br>IconCount = SendMessage(Hdesk, LVM_GETTITEMCOUNT, 0, 0)<br>Dim TR As Long, J As Long, Ji As Long<br>Dim RF As Long, Frt As Boolean, Rf1 As Long, FR As Boolean, LT As Boolean<br>Dim Rf2 As Long<br>LT = False<br>FR = False<br>Frt = False<br>TR = 0<br>J = 0<br>ReDim Pointx(IconCount)<br>For TR = 0 To IconCount - 1<br>Ji = Ji + 1<br><br>DoEvents<br>Ds: Select Case SX<br>Case "桌面图标左顶对齐"<br>Pointx(TR).y = 77 * (J + 1) - 77<br>Pointx(TR).X = 77 * Ji - 50<br>If Pointx(TR).X &gt; DeskWidth - 10 Then<br>Ji = 1<br>J = J + 1<br>GoTo Ds<br>End If<br>Case "桌面图标右顶对齐" '右顶对齐<br><br>Pointx(TR).y = 77 * (J + 1) - 77<br>Pointx(TR).X = DeskWidth - 77 * Ji + 10<br>If Pointx(TR).X &lt; 10 Then<br>Ji = 1<br>J = J + 1<br>GoTo Ds<br>End If<br>Case "桌面图标左对齐" '左对齐<br>Pointx(TR).y = 77 * Ji - 77<br>Pointx(TR).X = 77 * J + 10<br><br>If Pointx(TR).y &gt; DeskHeight - 40 Then<br>Ji = 1<br>J = J + 1<br>GoTo Ds<br>End If<br><br>Case "桌面图标右对齐" '右对齐<br><br>Pointx(TR).y = 77 * Ji - 77<br>Pointx(TR).X = DeskWidth - 77 * J - 77<br>If Pointx(TR).y &gt; DeskHeight - 40 Then<br>Ji = 1<br>J = J + 1<br>GoTo Ds<br>End If<br>Case "桌面图标左右环绕" '环绕<br>'左顶对齐<br>If ((DeskWidth - 77) &gt; (77 * Ji - 50)) And Frt = False Then<br>Pointx(TR).y = 0 '77 * (J + 1) - 77<br>Pointx(TR).X = 77 * Ji - 50<br>RF = Pointx(TR).X<br>Else<br>'右对齐<br>If Frt = False Then<br>Ji = 2<br>Frt = True<br>End If<br>If FR = False And ((DeskHeight - 40) &gt; (77 * Ji - 77)) Then<br>Pointx(TR).X = RF<br>Pointx(TR).y = 77 * Ji - 77<br>Rf1 = Pointx(TR).y<br>Else<br>'右底对齐<br>If FR = False Then<br>FR = True<br>Ji = 2<br>End If<br>If LT = False And DeskWidth - 77 * Ji &gt; 10 Then<br>Pointx(TR).y = Rf1<br>Pointx(TR).X = DeskWidth - 77 * Ji<br>Rf2 = Pointx(TR).X<br>Else<br>'左对齐<br>If LT = False Then<br>LT = True<br>Ji = 2<br>End If<br>Pointx(TR).X = Rf2<br>Pointx(TR).y = DeskHeight - 77 * Ji<br>End If<br>End If<br>End If<br>Case "桌面图标右底对齐" '右底对齐<br>Pointx(TR).X = DeskWidth - 77 * Ji<br>Pointx(TR).y = DeskHeight - 77 * (J + 1)<br>If Pointx(TR).X &lt; 10 Then<br>Ji = 1<br>J = J + 1<br>GoTo Ds<br>End If<br>End Select<br>SendMessageLong Hdesk, LVM_SETITEMPOSITION, TR, CLng(Pointx(TR).X + Pointx(TR).y * &amp;H10000)<br>Next TR<br>Erase Pointx()<br>End Sub<br><br>Public Function GetrDeskIconHandle() As Long<br>Dim Wnd As Long<br>Wnd = FindWindow("progman", vbNullString)<br>Wnd = FindWindowEx(Wnd, 0, "shelldll_defview", vbNullString)<br>Wnd = FindWindowEx(Wnd, 0, "syslistview32", vbNullString)<br>GetrDeskIconHandle = Wnd<br>End Function
 
在Form中添加ListView 然后右键跟踪到TListVIew生命的单元 然后查找ListView_GetITemText,找到使用者个函数的地方,然后右键跟踪,就找到生命的地方了,确实是通过SendMessage来模拟的
 
通过了,只要在 implementation 下加入 uses commctrl 就可以了!呵呵!
 
后退
顶部