Hallo Leute,
ich will die Beschriftungen der Icons im Desktop-Listview per API auslesen.
Ich habe schon einen Code erstellt, der mir dies von im eigenen Programm eingebauten
Listviews liefert. Jetzt will ich aber die Labels vom Desktop auslesen.
Was ich bisher gemacht habe, scheint nicht zu funktionieren. Hat einer
eine Ahnung warum? Obwohl ich die Sache mit dem Sharedmemory
beachtet habe (Da Desktop und eigenes Programm unterschiedliche Prozesse
haben, gelten die Pointer des Desktops im eigenen Programm nicht und
vice-versa). Bitte helft mir, ich bin am verzweifeln. Hier ist das, was ich bisher schon
gemacht habe:
Option Explicit
Private Declare Function ReadProcessMemory Lib "kernel32" (ByVal hProcess As _
Long, lpBaseAddress As Any, lpBuffer As Any, ByVal nSize As Long, _
lpNumberOfBytesWritten As Long) As Long
Private Declare Function WriteProcessMemory Lib "kernel32" (ByVal hProcess As _
Long, lpBaseAddress As Any, lpBuffer As Any, ByVal nSize As Long, _
lpNumberOfBytesWritten As Long) As Long
Private Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" ( _
ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) _
As Long
Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As _
Long, lpdwProcessId As Long) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal _
lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function FindWindowEx& Lib "user32" Alias "FindWindowExA" ( _
ByVal hWndParent As Long, ByVal hWndChildAfter As Long, ByVal lpClassName As _
String, ByVal lpWindowName As String)
Private Const LVM_FIRST = &H1000
Private Const LVM_GETITEM As Long = &H1000 + 5
Private Const LVIF_TEXT As Long = &H1
Private Type LV_ITEM
mask As Long
iItem As Long
iSubItem As Long
State As Long
stateMask As Long
pszText As String
cchTextMax As Long
iImage As Long
lParam As Long
iIndent As Long
End Type
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As _
Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Const PROCESS_VM_OPERATION = &H8
Const PROCESS_VM_READ = &H10
Const PROCESS_VM_WRITE = &H20
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, _
lpAddress As Any, ByVal dwSize As Long, ByVal dwFreeType As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As _
Long
Const MEM_COMMIT = &H1000
Const MEM_RESERVE = &H2000
Const MEM_RELEASE = &H8000
Private Const PAGE_READWRITE = &H4&
Private Sub cmdGetLbl_Click()
Dim lHwnD As Long
lHwnD = GetSysLVWHwnd
MsgBox GetLVWLabel(lHwnD, 1)
End Sub
Private Function GetSysLVWHwnd() As Long
Dim h As Long
h = FindWindow("Progman", vbNullString)
h = FindWindowEx(h, 0, "SHELLDLL_defVIEW", vbNullString)
GetSysLVWHwnd = FindWindowEx(h, 0, "SysListView32", vbNullString)
End Function
Private Function GetLVWLabel(lHwnD As Long, lNum As Long) As String
Dim pid As Long, tid As Long
Dim hProcess As Long, lpSysShared As Long, dwSize As Long
Dim lWritten As Long
Dim LV As LV_ITEM
tid = GetWindowThreadProcessId(lHwnD, pid)
lpSysShared = GetMemSharedNT(pid, Len(LV), hProcess)
With LV
.mask = LVIF_TEXT
.pszText = Space$(32)
.cchTextMax = Len(.pszText)
.iItem = lNum
End With
dwSize = Len(LV)
WriteProcessMemory hProcess, ByVal lpSysShared, LV, dwSize, lWritten
MsgBox SendMessage(lHwnD, LVM_GETITEM, 0&, ByVal lpSysShared)
ReadProcessMemory hProcess, ByVal lpSysShared, LV, dwSize, lWritten
GetLVWLabel = LV.pszText
FreeMemSharedNT hProcess, lpSysShared, Len(LV)
End Function
Private Function GetMemSharedNT(ByVal pid As Long, ByVal memSize As Long, _
hProcess As Long) As Long
hProcess = OpenProcess(PROCESS_VM_OPERATION Or PROCESS_VM_READ Or _
PROCESS_VM_WRITE, False, pid)
GetMemSharedNT = VirtualAllocEx(ByVal hProcess, ByVal 0&, ByVal memSize, _
MEM_RESERVE Or MEM_COMMIT, PAGE_READWRITE)
End Function
Private Sub FreeMemSharedNT(ByVal hProcess As Long, ByVal MemAddress As Long, _
ByVal memSize As Long)
Call VirtualFreeEx(hProcess, ByVal MemAddress, memSize, MEM_RELEASE)
CloseHandle hProcess
End Sub Wie gesagt, das soll unter WinNT/2k/XP funktionieren.
Danke im Voraus,
Marcus Sonntag
For VB Tools visit :: www.planetultra.de :: |