| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1500 人关注过本帖
标题:不完善的可以获取其它窗口内容的代码,
取消只看楼主 加入收藏
顾海洋凡
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2016-7-9
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:3 
不完善的可以获取其它窗口内容的代码,
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcId As Long) As Long '打开进程

Private Declare Function VirtualAllocEx Lib "kernel32" (ByVal hProcess As Long, ByVal lpAddress As Long, ByVal dwSize As Long, ByVal flAllocationType As Long, ByVal flProtect As Long) As Long                     '获取内存空间

Private Declare Function VirtualFreeEx Lib "kernel32" (ByVal hProcess As Long, ByVal lpAddress As Long, ByVal dwSize As Long, ByVal dwFreeType As Long) As Long '释放内存空间

Private Declare Function WriteProcessMemory Lib "kernel32" (ByVal hProcess As Long, ByVal lpBaseAddress As Any, ByVal lpBuffer As Any, ByVal nSize As Long, lpNumberOfBytesWritten As Long) As Long '向内存写数据

Private Declare Function ReadProcessMemory Lib "kernel32" (ByVal hProcess As Long, ByVal lpBaseAddress As Long, ByRef lpBuffer As Any, ByVal nSize As Long, lpNumberOfBytesWritten As Long) As Long '向内存读数据

Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByRef lParam As Any) As Long '发送消息

Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long '关闭进程

Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long '获得进程ID
'常数申明
 Const LVM_FIRST As Long = &H1000
 Const LVM_GETHEADER As Long = LVM_FIRST + 31
 Const LVM_GETITEMCOUNT As Long = LVM_FIRST + 4
 Const LVM_GETITEMTEXT As Long = LVM_FIRST + 45
 Const HDM_FIRST As Long = &H1200
 Const HDM_GETITEMCOUNT As Long = (HDM_FIRST + 0)
 Const PROCESS_VM_OPERATION As Long = &H8
 Const PROCESS_VM_READ As Long = &H10
 Const PROCESS_VM_WRITE As Long = &H20
 Const MAX_LVMSTRING As Long = 255
 Const MEM_COMMIT As Long = &H1000
 Const MEM_RELEASE As Long = &H8000&
 Const PAGE_READWRITE As Long = &H4
 Const LVIF_TEXT As Long = &H1
 Option Explicit
Private Type LV_ITEMA
    mask        As Long
    iItem        As Long
    iSubItem    As Long
    State        As Long
    stateMask    As Long
    pszText      As Long
    cchTextMax  As Long
End Type
 
'类型申明
Private Sub Form_Load()

End Sub

'API申明


Public Function GetListViewTextArray(ByVal hWindow As Long) As String()
  Dim myItem()           As LV_ITEMA
  Dim PHandle            As Long
  Dim ProcessId          As Long
  Dim PStrBufferMemory   As Long
  Dim PMyItemMemory      As Long
  Dim StrBuffer(MAX_LVMSTRING) As Byte
  Dim TmpString          As String
  Dim Ih As Long, J As Long, HCount As Long
  Dim StrArr() As String, ItemString As String
  Dim Ji As Long, MyItemLength() As Long

    GetWindowThreadProcessId hWindow, ProcessId
    HCount = SendMessage(hWindow, LVM_GETHEADER, 0, 0) '获取列数
    If HCount > 0 Then
        HCount = SendMessage(HCount, HDM_GETITEMCOUNT, 0, 0) - 1
      Else 'NOT HCOUNT...
        HCount = 0
    End If
    PHandle = OpenProcess(PROCESS_VM_OPERATION Or PROCESS_VM_READ Or PROCESS_VM_WRITE, 0, ProcessId)
    ReDim myItem(HCount)
    ReDim MyItemLength(HCount)
    PStrBufferMemory = VirtualAllocEx(PHandle, 0, MAX_LVMSTRING, MEM_COMMIT, PAGE_READWRITE)
    PMyItemMemory = VirtualAllocEx(PHandle, 0, MAX_LVMSTRING, MEM_COMMIT, PAGE_READWRITE)
    Ji = SendMessage(hWindow, LVM_GETITEMCOUNT, 0, 0) - 1
    On Error GoTo err1
    ReDim StrArr(Ji)
   
    For Ih = 0 To HCount
        myItem(Ih).mask = LVIF_TEXT
        myItem(Ih).iSubItem = Ih
        myItem(Ih).pszText = PStrBufferMemory
        myItem(Ih).cchTextMax = MAX_LVMSTRING
        MyItemLength(Ih) = Len(myItem(Ih))
    Next Ih
   
    For J = 0 To Ji
        ItemString = ""
        For Ih = 0 To HCount
            WriteProcessMemory PHandle, PMyItemMemory, myItem(Ih), MyItemLength(Ih), 0
            If SendMessage(hWindow, LVM_GETITEMTEXT, J, ByVal PMyItemMemory) > 0 Then
                ReadProcessMemory PHandle, PStrBufferMemory, StrBuffer(0), MAX_LVMSTRING, 0
                TmpString = StrConv(StrBuffer, vbUnicode)
                TmpString = Left(TmpString, InStr(TmpString, vbNullChar) - 1)
                ItemString = ItemString & TmpString & Chr(9) ' Chr$(32)
            End If
        Next Ih
        If ItemString <> "" Then
            StrArr(J) = Left(ItemString, Len(ItemString) - 1)
        End If
    Next J
   
    VirtualFreeEx PHandle, PMyItemMemory, 0, MEM_RELEASE
    VirtualFreeEx PHandle, PStrBufferMemory, 0, MEM_RELEASE
    CloseHandle (PHandle)
    ItemString = ""
    GetListViewTextArray = StrArr
   
    Exit Function
err1:
    MsgBox "不是Listview类吧?", vbInformation
End Function

请高手给完善一下,

搜索更多相关主题的帖子: 空间 
2016-08-02 21:38
顾海洋凡
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2016-7-9
收藏
得分:0 
回复 楼主 顾海洋凡
这个程序运行后,什么也不显示。请大侠给完善一下,
2016-08-02 21:39
顾海洋凡
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2016-7-9
收藏
得分:0 
回复 楼主 顾海洋凡
我想通过,窗口的类名,或是标题来得到该窗口的内容。不太好实现,请大家帮帮忙,
2016-08-03 14:24
顾海洋凡
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2016-7-9
收藏
得分:0 
回复 5楼 ZHRXJR
谢谢斑竹的提示,我先结贴吧,有问题再发新贴,
2016-08-06 15:50
快速回复:不完善的可以获取其它窗口内容的代码,
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.038552 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved