Autor Beitrag
wazap
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 25



BeitragVerfasst: Fr 27.02.09 00:16 
Hallo alle zusammen...

Ich habe mich gefragt wie das Tool "WinSpy" die Liste der Play-List vom WMP11 auslesen kann und wollte es natürlich auch gleich mal probieren!

Ein Freund von mir hat mir die Unit CommCtrl empfohlen, worin auch Funktionen zu TListView enthalten sind.
Ich kann aber nur den ItemCount auslesen oder Item Löschen, aber keine auslesen...

Könnt ihr mir vllt veraten wie das geht bzw. Tipps geben?

Mein bisherieger Code (Bringt WMP11 zum abstürzen):
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:
function GetWMP11PlayList(): HWND;
var
  WndMain, WndChild: HWND;
begin
  Result := 0;

  WndMain := FindWindow('WMPlayerApp''Windows Media Player');

  if WndMain <> 0 then
  begin
    WndChild := FindWindowEx(WndMain, 0'WMPAppHost'NIL);
    WndChild := FindWindowEx(WndChild, 0'WMP Skin Host'NIL);
    WndChild := FindWindowEx(WndChild, 0'ATL:131D3790'NIL);
    WndChild := FindWindowEx(WndChild, 0'SysListView32'NIL);

    if WndChild <> 0 then
      Result := WndChild;
  end;
end;

procedure TForm1.FormCreate(Sender: TObject);
var
  WMP11: HWND;
  Count,
  Len: Integer;

  Buffer: PChar;
begin
  WMP11 := GetWMP11PlayList;

  Count := ListView_GetItemCount(WMP11);
  Len := ListView_GetItemText(WMP11, 0,0, Buffer, 255);

  Memo1.Lines.Add('Count: ' + IntToStr(Count));
  Memo1.Lines.Add('Length: ' + IntToStr(Len));
  Memo1.Lines.Add(string(@Buffer));
end;
wazap Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 25



BeitragVerfasst: Do 05.03.09 22:20 
Weiß keiner mir zu helfen?

Gruß
Mr_Emre_D
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 114
Erhaltene Danke: 14



BeitragVerfasst: So 08.03.09 00:03 
Du hättest dir auch selber mühe geben können ...

Aber ich will heute nicht so sein :P

Viel Spaß damit.

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:
  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, 00 );
  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;


EDIT:
Vlt ist noch wichtig zu wissen, bei welcher Version es 100% funzt:
Windows Media Player Version 11.0.6000.6344

Du müsstest halt einfach anders bei anderen Versionen nach dem Handle suchen.

MfG Emre
wazap Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 25



BeitragVerfasst: So 08.03.09 12:23 
Mühe war schon bei meim ersten Code zu viel drin. ^^ In diese richtung beim Programmieren bin ich noch nie gegangen!

Vielen Dank!!