axWindowsMediaPlayer with custom contextMenuStrip

It's not that I'm getting an error. If I place a axWindowsMediaPlayer and a contextMenuStrip on a form and then connect the contextMenuStrip to the axWindowsMediaPlayer via the contextMenuStrip property on the axWindowsMediaPlayer property page and run the app I get the context menu that normally comes with media player (pause/play, stop, etc). If I set the enableContextMenu property for the axWindowsMediaPlayer control I get no contextMenu at all.

I get the same results if I do thisprogrammaticallyvs. the property sheet settings.

What I want is my own contextMenu. If I can modify the one that exists or add my own I'd be happy.

Thanks,

Jack

[780 byte] By [Jack.Johnson.DelMar] at [2008-1-9]
# 1

You can create a custom control derive from AxWindowsMediaPlayer class, override its WndProc method to filter the WM_RBUTTONDOWN message, i.e. when right mouse button clicks, to show your custom ContextMenuStrip.
Create a class, paste my *myMediaPlayer* class code below into it, build, then use this myMediaPlayer control instead of the standard one, to suppress the standard context menu, set the enableContextMenu property to false.

Code Snippet

public partial class Form8 : Form

{

public Form8()

{

InitializeComponent();

}

private void Form8_Load(object sender, EventArgs e)

{

this.axWindowsMediaPlayer1.enableContextMenu = false;

this.axWindowsMediaPlayer1.CustomContextMenu = this.contextMenuStrip1;

}

}

class myMediaPlayer : AxWMPLib.AxWindowsMediaPlayer

{

private ContextMenuStrip _contextMenu;

public ContextMenuStrip CustomContextMenu

{

get { return this._contextMenu; }

set { this._contextMenu = value; }

}

protected override void WndProc(ref Message m)

{

if (m.Msg == 0x0204)// WM_RBUTTONDOWN

{

if (this._contextMenu != null)

{

//Get cursor position(in client coordinates)

Int16 x = (Int16)m.LParam;

Int16 y = (Int16)((int)m.LParam >> 16);

Point cursorPosition = new Point(x, y);

this._contextMenu.Show(this, cursorPosition);

}

}

base.WndProc(ref m);

}

}

Zhi-XinYe-MSFT at 2007-10-2 > top of Msdn Tech,Windows Forms,Windows Forms General...