[delphi] Uchwyt do ListView

0

Mam pytanko, jakiego komunikatu użyć do pobrania Itema z ListView innego okna, bo niezbyt widze odpowiedni komunikat w delphi...

0

jakiego innego okna? Może byś tak napisał dokłądniej o co Ci chodzi

0

Funkcja:

uses CommCtrl;

function GetListViewItemText(ListViewHandle:HWND; ItemNumber:integer; SubItemNumber:integer):string;
var item:tagLVITEMA;
    text:array[0..31] of char;
begin
ZeroMemory(@item, sizeof(item));
item.iItem:=ItemNumber;
item.iSubItem:=SubItemNumber;
item.pszText:=text;
item.mask:=LVIF_TEXT;
item.cchTextMax:=sizeof(text);
SendMessage(ListViewHandle, LVM_GETITEM, 0, Integer(@item));
result:=text;
end;

Użycie:

Caption:=GetListViewItemText(ListView1.Handle, 1, 0);
0

Dzieki ! Ale niestety wiem czemu mi to nie smigalo wszystko bo juz to wczesniej zrobilem podobnie jak ty. W tym "innym" programie jest jakis chyba niestandardowy ListView i dlatego nie moge z niego danych wyciagnac :) :(((

0

Jednak to chyba nie jest niestandardowy ListView... bo teraz zrobilem przykladowy programik w delphi z jednym ListView wszystko standardowo tylko dane dopisalem, dwa itemy po dwa SubItemy i zrobilem tak:


function TForm1.GetListViewItemText(ListViewHandle:HWND; ItemNumber:integer; SubItemNumber:integer):string;
var item:tagLVITEMA;
    text:array[0..31] of char;
begin
  ZeroMemory(@item, sizeof(item));
  item.iItem:=ItemNumber;
  item.iSubItem:=SubItemNumber;
  item.pszText:=text;
  item.mask:=LVIF_TEXT;
  item.cchTextMax:=sizeof(text);
  SendMessage(ListViewHandle, LVM_GETITEM, 0, Integer(@item));
  result:=text;
end;

procedure TForm1.XiButton1Click(Sender: TObject);
var
  hWindow, hList: HWND;
begin
  hWindow:= FindWindow('TForm1', 'Form1');
  hList:= FindWindowEx(hWindow, 0, 'TListView', nil);
  Caption:= GetListViewItemText(hList, 0, 0);
end;

I z innego programu juz nie chce pobrac tylko jakies krzaki są... jezeli listView jest w tym samym programie w ktorym pobieramy itema to dziala..</delphi>

0

Ale najpierw musisz funkcję wywołać w ramach pamięci adresowej tego procesu z ListView. Myślałem, że to oczywiste.

Poszukaj o tym na forum, było nawet ostatnio.

http://www.codeproject.com/threads/winspy.asp

0

Dość ze po angolu to jeszcze w C++ :( takie opisy z "jezykiem technicznym" to niezbyt lapie, nie ma jakiegos prostego sposobu na to albo polskiego opisu?

0
function Tdaasd.GetListViewItemText(ListViewHandle:HWND; ItemNumber:integer; SubItemNumber:integer):string;
var item:tagLVITEMA;
    text:array[0..31] of char;
begin
  ZeroMemory(@item, sizeof(item));
  item.iItem:=ItemNumber;
  item.iSubItem:=SubItemNumber;
  item.pszText:=text;
  item.mask:=LVIF_TEXT;
  item.cchTextMax:=sizeof(text);
  SendMessage(ListViewHandle, LVM_GETITEM, 0, Integer(@item));
  result:=text;
end;

procedure Tdaasd.XiButton1Click(Sender: TObject);
var
  hWindow, hList: HWND;
  pLibRemote: Pointer;
  szLibPath: array[0..MAX_PATH] of Char;
  hProcess, Bytes, ThreadId: cardinal;
  hLibModule: DWORD;
  hThread: THandle;
  hKernel32: HMODULE;
begin
  hWindow:= FindWindow('TForm1', 'Form1');
  hList:= FindWindowEx(hWindow, 0, 'TListView', nil);

  szLibPath:='C:\Documents and Settings\Max\Pulpit\Nowy folder\LibSpy.dll';

  hKernel32:= GetModuleHandle('Kernel32');
  pLibRemote := VirtualAllocEx(hProcess, nil, sizeof(szLibPath),
                               MEM_COMMIT, PAGE_READWRITE );

  WriteProcessMemory( hProcess, pLibRemote, @szLibPath,
                      sizeof(szLibPath), Bytes );

  hThread := CreateRemoteThread( hProcess, nil, 0, GetProcAddress( hKernel32, 'LoadLibraryA' ), nil, ThreadId, ThreadId);
  WaitForSingleObject( hThread, INFINITE );

  Caption:= GetListViewItemText(hList, 1, 1);

  GetExitCodeThread( hThread, hLibModule );

  CloseHandle( hThread );
  VirtualFreeEx( hProcess, pLibRemote, sizeof(szLibPath), MEM_RELEASE );
end;

Cos takiego wykombinowalem z tego opisu wiem ze zle, ale moze ktos mi objasni o co w tym biega i jak to poprawic :)... fajna rzecz zauwazylem :P ze w zleznosci od polozenia "Caption:= GetList..." zmieniaja sie krzaczki [rotfl] [rotfl] [rotfl] ...

Sorry ze nie edytuje postow ale nie moge sie zalogowac na swoje konto

0

Dobra udało mi sie zalogować , teraz będe edytował jak cos...
Troche zrozumiałem to Inject Dll, ale nadal mi to nie działa o to kodzik jak zrobiłem:

Program:

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, XiButton, CommCtrl, StdCtrls, TLHelp32;

type
  TMainForm = class(TForm)
    XiButton1: TXiButton;
    procedure XiButton1Click(Sender: TObject);
  private
    procedure InjectDll(hProcess: THandle);
    { Private declarations }
  public
    { Public declarations }
  end;

var
  MainForm: TMainForm;

  function Dane: String; stdcall external 'Project2.dll' name 'Dane';
implementation

{$R *.dfm}

procedure TMainForm.XiButton1Click(Sender: TObject);
var
  hProcess: THandle;
  _HWND : THandle;
  Proc : TProcessEntry32;
begin
  _HWND := CreateToolHelp32SnapShot(TH32CS_SNAPALL,0);

  Proc.dwSize:=SizeOf(Proc); // okresl rozmiar struktory

  if Integer(Process32First(_HWND, Proc)) <> 0 then
  repeat
    if proc.szExeFile = 'Project3.exe' then
    begin
      hProcess:= OpenProcess(PROCESS_CREATE_THREAD + PROCESS_QUERY_INFORMATION + PROCESS_VM_OPERATION + PROCESS_VM_WRITE + PROCESS_VM_READ, false, Proc.th32ProcessID);
      Break;
    end;
  until Integer(Process32Next(_HWND, Proc)) = 0; // dopoki wartosc nie osiagnie 0

  CloseHandle(_HWND);


  
  InjectDll(hProcess);

  Showmessage(Dane);

  CloseHandle(hProcess);

end;

procedure TMainForm.InjectDll(hProcess: THandle);
var
  pLibRemote: Pointer;
  szLibPath: array[0..MAX_PATH] of Char;
  Bytes, ThreadId: cardinal;
  hLibModule: DWORD;
  hThread: THandle;
  hKernel32: HMODULE;
begin
  hLibModule:=0;
  pLibRemote:= nil;

  hKernel32:= GetModuleHandle('Kernel32');
  szLibPath:='C:\Documents and Settings\Max\Pulpit\Nowy folder\Project2.dll';

  pLibRemote := VirtualAllocEx(hProcess, nil, sizeof(szLibPath),
                               MEM_COMMIT, PAGE_READWRITE );

  WriteProcessMemory( hProcess, pLibRemote, @szLibPath,
                      sizeof(szLibPath), Bytes );

  hThread := CreateRemoteThread( hProcess, nil, 0, GetProcAddress( hKernel32, 'LoadLibraryA' ), nil, ThreadId, ThreadId);
  WaitForSingleObject( hThread, INFINITE );

  GetExitCodeThread( hThread, hLibModule );

  CloseHandle( hThread );
  VirtualFreeEx( hProcess, pLibRemote, sizeof(szLibPath), MEM_RELEASE );
end;

end.

Biblioteka DLL (Project2.Dll):

library Project2;

{ Important note about DLL memory management: ShareMem must be the
  first unit in your library's USES clause AND your project's (select
  Project-View Source) USES clause if your DLL exports any procedures or
  functions that pass strings as parameters or function results. This
  applies to all strings passed to and from your DLL--even those that
  are nested in records and classes. ShareMem is the interface unit to
  the BORLNDMM.DLL shared memory manager, which must be deployed along
  with your DLL. To avoid using BORLNDMM.DLL, pass string information
  using PChar or ShortString parameters. }

uses
  SysUtils,
  Classes, Windows, CommCtrl;

var
  Uchwyt: HWND;
  Haslo: String;

{$R *.res}

procedure Dll_Proc(Reason : Integer);
var
  hWindow, hList: HWND;
  item:tagLVITEMA;
  text: array[0..31] of char;
begin
  if Reason <> DLL_PROCESS_ATTACH then Exit;

  hWindow:= FindWindow('TForm1', 'Form1');
  hList:=FindWindowEx(hWindow, 0, 'TListView', nil);
  Uchwyt:= hList;

  ZeroMemory(@item, sizeof(item));
  item.iItem:=0;
  item.iSubItem:=0;
  item.pszText:=text;
  item.mask:=LVIF_TEXT;
  item.cchTextMax:=sizeof(text);
  SendMessage(Uchwyt, LVM_GETITEM, 0, Integer(@item));

  Haslo:=text;
end;

function Dane: String;
begin
  Result:= Haslo;
end;


exports
  Dane name 'Dane';

begin
end.

I otrzymuje pusty komunikat...

0

nikt nie potrafi pomoc:(??

1 użytkowników online, w tym zalogowanych: 0, gości: 1