Registriert seit: 8. Apr 2004
183 Beiträge
Delphi 7 Enterprise
|
Re: In die Listbox eines anderen Programmes adden / deleten
10. Jan 2006, 08:10
Delphi-Quellcode:
function GetItemIndex(aText : String; const CaseSensitive : Boolean = FALSE) : Integer;
function GetListView : Cardinal;
begin
// sollte von dir angepasst werden
result := FindWindow(nil,'Form1');
result := FindWindowEx(result, 0, 'TListView', nil);
end;
var
ListView: HWND;
ProcessId: DWORD;
Process: THandle;
Size: Cardinal;
MemLocal: Pointer;
MemRemote: Pointer;
NumBytes: Cardinal;
IconIndex: Integer;
IconLabel: string;
begin
result := 0;
ProcessId := 0;
ListView := GetListView;
GetWindowThreadProcessId(ListView, @ProcessId);
Process := OpenProcess(PROCESS_VM_OPERATION or PROCESS_VM_READ or
PROCESS_VM_WRITE, False, ProcessId);
if (Process <> 0) then
try
Size := SizeOf(TLVItem) + SizeOf(Char) * MAX_PATH + 1;
MemLocal := VirtualAlloc(nil, Size, MEM_RESERVE or MEM_COMMIT,
PAGE_READWRITE);
MemRemote := VirtualAllocEx(Process, nil, Size, MEM_RESERVE or MEM_COMMIT,
PAGE_READWRITE);
if Assigned(MemLocal) and Assigned(MemRemote) then
try
for IconIndex := 0 to SendMessage(ListView, LVM_GETITEMCOUNT, 0, 0) - 1 do
begin
ZeroMemory(MemLocal, SizeOf(TLVItem));
with PLVItem(MemLocal)^ do
begin
mask := LVIF_TEXT;
iItem := IconIndex;
pszText := LPTSTR(Cardinal(MemRemote) + Cardinal(SizeOf(TLVItem)));
cchTextMax := MAX_PATH;
end;
NumBytes := 0;
if WriteProcessMemory(Process, MemRemote, MemLocal, Size, NumBytes) and
Boolean(SendMessage(ListView, LVM_GETITEM, 0, LPARAM(MemRemote))) and
ReadProcessMemory(Process, MemRemote, MemLocal, Size, NumBytes) then
begin
IconLabel := string(
PChar(Cardinal(MemLocal) + Cardinal(SizeOf(TLVItem))));
if CaseSensitive then
begin
IconLabel := LowerCase(IconLabel);
aText := LowerCase(aText);
end;
if IconLabel = aText then
begin
Result := IconIndex;
exit;
end;
end;
end;
except
end;
if Assigned(MemRemote) then
VirtualFreeEx(Process, MemRemote, 0, MEM_RELEASE);
if Assigned(MemLocal) then
VirtualFree(MemLocal, 0, MEM_RELEASE);
finally
CloseHandle(Process);
end;
end;
(17:05:33) ( deccer ) duuu keine ahnung vonski?
(17:05:46) ( deccer ) duuuu ober dörticode schreibsorinski?
(17:06:02) ( deccer ) bist doch schlimmor wie uall :F
>> brechi : Livecracking is shice, da sieht man immer die Fehler <<
|