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:
| PLVItem = ^TLVItem; TLVITEM = 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; ItemText: Array[Byte] of Char; end;
TWMPPlaylistEntries = Array of String;
const LVM_FIRST = $1000; LVM_GETITEMCOUNT = LVM_FIRST + $04; LVM_GETITEM = LVM_FIRST + $05; LVM_SETITEM = LVM_FIRST + $06; LVM_GETITEMPOSITION = LVM_FIRST + $10; LVM_SETITEMPOSITION = LVM_FIRST + $0F;
---
function GetWMPPlaylistEntries( hWMPPlayList: Cardinal ): TWmpPlayListEntries; var i : Integer; Items : Cardinal; PID : Cardinal; hProc : Cardinal; Buf : PLVItem; pBuf : PChar; dwBuf : Cardinal; MEM : PLVItem; begin Items := SendMessage( hWMPPlayList, LVM_GETITEMCOUNT, 0, 0 ); if Items > 0 then begin GetWindowThreadProcessID( hWMPPlayList, PID ); New( Buf ); GetMem( pBuf, MAX_PATH ); try hProc := OpenProcess( PROCESS_ALL_ACCESS, False, PID ); Mem := VirtualAllocEx( hProc, nil, MAX_PATH, MEM_COMMIT, PAGE_READWRITE ); FillChar(Buf^, SizeOf(TLVItem), #00); for i := 0 to Items-1 do begin with Buf^ do begin mask := 1; iItem := i; pszText := Cardinal(MEM)+SizeOf(TLVItem)-256; cchTextMax := 256; end; WriteProcessMemory( hProc, MEM, Buf, SizeOf(Buf^), dwBuf ); SetLength( Result, Length(Result)+1 ); SendMessage( hWMPPlayList, LVM_GETITEM, 0, Cardinal(MEM) ); ReadProcessMemory( hProc, MEM, Buf, SizeOf(Buf^), dwBuf ); Result[High(Result)] := String(Buf^.ItemText); end; VirtualFreeEx( hProc, Mem, MAX_PATH, MEM_DECOMMIT ); finally CloseHandle( hProc ); FreeMem( pBuf, MAX_PATH ); Dispose( Buf ); end; end; end;
procedure TForm1.Button1Click(Sender: TObject); var i: Integer; hWnd: Cardinal; Playlist: TWmpPlayListEntries; begin hWnd := FindWindow( 'WMPlayerApp', 0 ); hWnd := FindWindowEx( hWnd, 0, 'WMPAppHost', 0 ); hWnd := FindWindowEx( hWnd, 0, 'WMP Skin Host', 0 ); hWnd := FindWindowEx( hWnd, 0, 'ATL:67CAB8C0', 'LibraryContainer' ); hWnd := FindWindowEx( hWnd, 0, 'SysListView32', 'BasketListView' ); if hWnd <> 0 then begin Playlist := GetWMPPlayListEntries( hWnd ); Listbox1.Clear; for i := 0 to High( PlayList ) do Listbox1.Items.Add( Playlist[i] ); end; end; |