getting number of items from curr playlist of windows media player

P

Paul Fi

I have this code which tries to obtain the number of items in the
current playlist of windows media player:

private void MainForm_Load(object sender, System.EventArgs e)
{
// get Window handle
wnd = Win32.FindWindow("WMPlayerApp","Windows Media Player");
wnd = Win32.FindWindowEx(wnd, 0, "WMPAppHost", null);
wnd = Win32.FindWindowEx(wnd, 0, "WMP Skin Host", null);
wnd = Win32.FindWindowEx(wnd, 0, "CWmpControlCntr", null);
wnd = Win32.FindWindowEx(wnd, 0, "WMPPlaylist", null);
wnd = Win32.FindWindowEx(wnd, 0, "ATL:SysListView32", null);

iHandle = Win32.FindWindow("WMPlayerApp", "Windows Media Player");
}

private void button1_Click(object sender, System.EventArgs e)
{
han =Win32.SendMessage(wnd, Win32.LB_GETCOUNT, 0,0);
if(han != Win32.LB_ERR)
{
textBox1.Text = Convert.ToString(han);
}
}

so when i click the button1 i should get the number of items displayed
in my textbox1.
but all i get is 0 even though my current playlist has 5 items and one
of them is currently playing.
has any body any idea why this is happening?
 
V

Vadym Stetsyak

Maybe beacuse the code in MainForm_Load cannot find specified window?
There can be different reasons why this is happening:
- there is not such window ( check windows with Spy++ tool )
- bug in the Win32 class

Also you do not check if
wnd = Win32.FindWindow("WMPlayerApp","Windows Media Player");
returned valid wnd handle.
 
P

Paul Fi

no it can find the window because i can send other messages like
play/pause and stop playing messages to windows media player current
track, but getcount message is returning 0
 
V

Vadym Stetsyak

did you check the result of
wnd = Win32.FindWindowEx(wnd, 0, "ATL:SysListView32", null);
can you call GetLastError if the han is equal to LB_ERR?
 
P

Paul Fi

dude its in the code above if it was ERR it wont assign the text value
of the han to the textbox1 that is why its returning 0 to the
textbox.text proprty
 
P

Paul Fi

im writing a C# program that tries to get the currently playing song in
a
seperate windows media player instance (external app)

i found out that there might be a way to do that using the windows
messaging
system.

some how i was able to use the win32 funtion findwindow() to get the
handle
for windows media player host, systemlistview32 and for wmpplaylist
using
spy++.

but now im trying to use the win32 function sendmessage() to get at
least
the index of the currently playing song in windows media player, and i
still
cant figure this out

does anyone know how to do that?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top