vb@rchiv
VB Classic
VB.NET
ADO.NET
VBA
C#
sevAniGif - als kostenlose Vollversion auf unserer vb@rchiv CD Vol.5  
 vb@rchiv Quick-Search: Suche startenErweiterte Suche starten   Impressum  | Datenschutz  | vb@rchiv CD Vol.6  | Shop Copyright ©2000-2025
 
zurück

 Sie sind aktuell nicht angemeldet.Funktionen: Einloggen  |  Neu registrieren  |  Suchen

VB & Windows API
Labels der Items im Desktoplistview auslesen (Win2k/XP)? 
Autor: planetULTRA
Datum: 21.08.03 16:23

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 ::

alle Nachrichten anzeigenGesamtübersicht  |  Zum Thema  |  Suchen

 ThemaViews  AutorDatum
Labels der Items im Desktoplistview auslesen (Win2k/XP)?3.263planetULTRA21.08.03 16:23
Re: Labels der Items im Desktoplistview auslesen (Win2k/XP)?1.429michi-bib21.08.03 22:04
Re: Labels der Items im Desktoplistview auslesen (Win2k/XP)?1.286E722.08.03 12:02
Re: Labels der Items im Desktoplistview auslesen (Win2k/XP)?1.528ModeratorMartoeng22.08.03 17:17
Re: Labels der Items im Desktoplistview auslesen (Win2k/XP)?1.380michi-bib23.08.03 06:05
Re: Labels der Items im Desktoplistview auslesen (Win2k/XP)?1.244Mr. Fox23.08.03 17:55
Re: Labels der Items im Desktoplistview auslesen (Win2k/XP)?2.148planetULTRA23.08.03 22:05
Re: Labels der Items im Desktoplistview auslesen (Win2k/XP)?1.273CyberDreams01.04.04 12:40
Re: Labels der Items im Desktoplistview auslesen (Win2k/XP)?1.207planetULTRA01.04.04 14:13
Re: Labels der Items im Desktoplistview auslesen (Win2k/XP)?1.371planetULTRA01.04.04 14:23
Re: Labels der Items im Desktoplistview auslesen (Win2k/XP)?1.314planetULTRA01.04.04 14:27
Re: Labels der Items im Desktoplistview auslesen (Win2k/XP)?1.542CyberDreams01.04.04 14:35

Sie sind nicht angemeldet!
Um auf diesen Beitrag zu antworten oder neue Beiträge schreiben zu können, müssen Sie sich zunächst anmelden.

Einloggen  |  Neu registrieren

Funktionen:  Zum Thema  |  GesamtübersichtSuchen 

nach obenzurück
 
   

Copyright ©2000-2025 vb@rchiv Dieter Otter
Alle Rechte vorbehalten.
Microsoft, Windows und Visual Basic sind entweder eingetragene Marken oder Marken der Microsoft Corporation in den USA und/oder anderen Ländern. Weitere auf dieser Homepage aufgeführten Produkt- und Firmennamen können geschützte Marken ihrer jeweiligen Inhaber sein.

Diese Seiten wurden optimiert für eine Bildschirmauflösung von mind. 1280x1024 Pixel