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 - 1] of Byte; case Integer of 0: (AnsiText: array[0..ItemBufferBlockSize - 1] of AnsiChar); 1: (WideText: array[0..ItemBufferBlockSize div 2 - 1] of WideChar); 2: (ItemText: array[0..ItemBufferBlockSize div SizeOf(Char) - 1] of 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; MemLocal : PLvItemBuffer; MemRemote : PLvItemBuffer; NumBytes : Cardinal; 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); Process := OpenProcess(PROCESS_QUERY_INFORMATION or PROCESS_VM_OPERATION or PROCESS_VM_READ or PROCESS_VM_WRITE, False, ProcessId); if Process <> 0 then try 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 IconCount := ListView_GetItemCount(hDesktopLV); for i := 0 to IconCount - 1 do begin 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) and Boolean(SendMessage(hDesktopLV, LVM_GETITEM, 0, LPARAM(MemRemote))) and ReadProcessMemory(Process, MemRemote, MemLocal, Size, NumBytes) then begin Callback(string(MemLocal^.ItemText)); 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 else begin Str(GetLastError, s); Callback(s); end; end;
begin GetDesktopCaptions(@Callback); Readln; end. |