Autor Beitrag
idefix123456
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 23



BeitragVerfasst: So 23.01.11 12:18 
Hallo,

ich Programmiere inzwischen schon länger mit Delphi. Allerdings möchte ich jetzt eine ListView eines anderen Programms auslesen. Doch das auslesen übersteigt irgendwie meine Logik und genau genommen verstehe ich bei diesem Problem eigentlich nur Bahnhof... Bisher habe ich durch WinSpy folgenden Code erhalten:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
var
  wndMain, wndChild: HWND;
begin
  wndMain := FindWindow('CustomDlg','TrueCrypt');
  if wndMain <> 0 then
  begin
    wndChild := FindWindowEx(wndMain, 0'SysListView32'nil);
    if wndChild <> 0 then
    begin
      ShowMessage('Window Handle: ' + IntToStr(wndChild));
      FlashControl(wndChild); // internal function
    end;
  end;
end.



Mein Compiler liefert zuerst einmal einen fehler mit dem "FlashControl". Entferne ich diese Zeile, erhalte ich das handle des Fensters.
Wie es den Anschein hat ist dieses handle auch immer die Gleiche Zahl?!.


Ich möchte eigentlich nur, das der Inhalt des ListView des anderen Programmes, auch in meinem Programm angezeigt wird. Am Besten in einer ListBox.

Wie bekomme ich jetzt allerdings den Inhalt in mein Programm rüber. Wie bekomme ich von der Handle Zahl den Inhalt. Habe auch was von ReadProcessMemory gelesen aber dann verstehe dann überhaupt nix mehr... Wer kann mir helfen

Danke für Antworten
Luckie
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: So 23.01.11 13:11 
idefix123456 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 23



BeitragVerfasst: Di 25.01.11 15:32 
Hallo,

Danke für deine Antwort. Das bei dem Link verwendete Programm ist nicht schlecht, allerdings funktioniert es in meinem Fall nicht!

ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
program ComCtrl32_Access_Demo;

{$APPTYPE CONSOLE}

uses
  Windows,
  Messages,
  CommCtrl;

const
  ItemBufferBlockSize = $1000;

type
  TCallback = function(Capion: string): Boolean; stdcall;

type
  PLvItemBuffer = ^TLvItemBuffer;
  TLvItemBuffer = packed record
    case Integer of
      0: (
        LvItem32: packed record
          mask: LongWord;
          iItem: LongInt;
          iSubItem: LongInt;
          state: LongWord;
          stateMask: LongWord;
          pszText: LongWord;
          cchTextMax: LongInt;
          iImage: LongInt;
          lParam: LongWord;
          iIndent: LongInt;
          iGroupId: LongInt;
          cColumns: LongWord;
          puColumns: LongWord
        end);
      1: (LvItemBuff: array[0..ItemBufferBlockSize - 1of Byte;
        case Integer of
          0: (AnsiText: array[0..ItemBufferBlockSize - 1of AnsiChar);
          1: (WideText: array[0..ItemBufferBlockSize div 2 - 1of WideChar);
          2: (ItemText: array[0..ItemBufferBlockSize div SizeOf(Char) - 1of
            Char));
  end;

function Callback(Caption: string): Boolean; stdcall;
begin
  Writeln(Caption);
  Result := True;
end;

procedure GetDesktopCaptions(Callback: TCallback); stdcall;
var
  s                 : string;
  hDesktopLV        : THandle;
  ProcessID         : DWORD;
  Process           : THandle;
  Size              : Cardinal; // SIZE_T
  MemLocal          : PLvItemBuffer;
  MemRemote         : PLvItemBuffer;
  NumBytes          : Cardinal; // SIZE_T
  IconCount         : DWORD;
  i                 : Integer;

  function GetDesktopListView: HWND;
  var
    wnd             : HWND;
  begin
    wnd := FindWindow('CustomDlg','TrueCrypt');
    if wnd <> 0 then
      wnd := FindWindowEx(wnd, 0'SysListView32'nil);
    Result := wnd;
  end;

begin
  hDesktopLV := GetDesktopListView;
  if hDesktopLV <> 0 then
  begin
    ProcessId := 0;
    GetWindowThreadProcessId(hDesktopLV, @ProcessId);
    // Prozess öffnen
    Process := OpenProcess(PROCESS_QUERY_INFORMATION or PROCESS_VM_OPERATION or
      PROCESS_VM_READ or PROCESS_VM_WRITE, False, ProcessId);
    if Process <> 0 then
    try
      // Lokalen und entfernten (im Zielprozess) Puffer anlegen
      Size := SizeOf(TLvItemBuffer);
      MemLocal := VirtualAlloc(nil, Size, MEM_COMMIT, PAGE_READWRITE);
      MemRemote := VirtualAllocEx(Process, nil, Size, MEM_COMMIT, PAGE_READWRITE);
      if Assigned(MemLocal) and Assigned(MemRemote) then
      try
        // Anzahl der Symbole ermitteln und in einer Schleife durchlaufen
        IconCount := ListView_GetItemCount(hDesktopLV);
        for i := 0 to IconCount - 1 do
        begin
          // TLvItemBuffer-Struktur initialisieren
          ZeroMemory(MemLocal, SizeOf(TLvItemBuffer));
          with MemLocal^ do
          begin
            LVItem32.mask := LVIF_TEXT;
            LVItem32.iItem := i;
            LVItem32.pszText := Cardinal(MemRemote) + ItemBufferBlockSize;
            LVItem32.cchTextMax := High(MemLocal.ItemText) + 1;
          end;
          NumBytes := 0;
          if WriteProcessMemory(Process, MemRemote, MemLocal, Size, NumBytes) // Struktur in den Remoteprozess kopieren
            and
            Boolean(SendMessage(hDesktopLV, LVM_GETITEM, 0, LPARAM(MemRemote))) // Struktur im Remoteprozess füllen
            and
            ReadProcessMemory(Process, MemRemote, MemLocal, Size, NumBytes) // Struktur in die lokale Struktur kopieren
            then
          begin
            // Callback mit Icontext zur Ausgabe aufrufen
            Callback(string(MemLocal^.ItemText));
          end;
        end;
      except
        // Exceptions ignorieren
      end;
      // Aufräumen
      if Assigned(MemRemote) then
        VirtualFreeEx(Process, MemRemote, 0, MEM_RELEASE);
      if Assigned(MemLocal) then
        VirtualFree(MemLocal, 0, MEM_RELEASE);
    finally
      CloseHandle(Process);
    end;
  end
  else
  begin
    Str(GetLastError, s);
    Callback(s);
  end;
end;

begin
  GetDesktopCaptions(@Callback);
  Readln;
end.



Leider Habe ich keine Ahnung wie der Obere Code Funktionieren soll, deswegen habe ich vermutlich irgendwo nur einen kleinen fehler...