Question

In my democode an embeded windows media player starts to load and play a video. The player shows no controls, all other options are the default options. So far this works.

What does not work is that not all userinteraction is stopped. For instance it is possible to change the mode to fullscreen with a doubleclick and it also is possible to get a full context with a right click.

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
        axWindowsMediaPlayer1.uiMode = "none";
    }

    private void button1_Click(object sender, EventArgs e)
    {
        axWindowsMediaPlayer1.URL = @"C:\stackoverflow.mp4";
    }
}

How can i isolate the player from the user and only control the player via code?

Was it helpful?

Solution 2

A friend just helped me to solve this.

Disabling the context menü was rather easy

axWindowsMediaPlayer1.enableContextMenu = false;

Disabling the doubleclick requires a message filter - there is already a solution on the web.

Application.AddMessageFilter((IMessageFilter)CustomFilter(this/*Form*/, axWMP));

I have rewritten my example and i am now using this code:

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
        axWindowsMediaPlayer1.uiMode = "none";
        axWindowsMediaPlayer1.enableContextMenu = false;
        Application.AddMessageFilter(new IgnoreMouseClickMessageFilter(this, axWindowsMediaPlayer1));
    }

    private void button1_Click(object sender, EventArgs e)
    {
        axWindowsMediaPlayer1.URL = @"C:\stackoverflow.mp4";
    }
}

class IgnoreMouseClickMessageFilter : IMessageFilter
    {
        private Control parent { get; set; }
        private Control target { get; set; }

        public IgnoreMouseClickMessageFilter(Control parent, Control target)
        {
            this.parent = parent;
            this.target = target;
        }

        public bool PreFilterMessage(ref Message messageBeforeFiltering)
        {
            const Boolean FilterTheMessageOut = true;
            const Boolean LetTheMessageThrough = false;

            if (IsNull(parent)) return LetTheMessageThrough;
            if (IsNull(target)) return LetTheMessageThrough;
            if (WasNotClickedOnTarget(parent, target)) return LetTheMessageThrough;
            if (MessageContainsAnyMousebutton(messageBeforeFiltering)) return FilterTheMessageOut;
            return LetTheMessageThrough;
        }

        private bool MessageContainsAnyMousebutton(Message message)
        {
            if (message.Msg == 0x202) return true; /* WM_LBUTTONUP*/
            if (message.Msg == 0x203) return true; /* WM_LBUTTONDBLCLK*/
            if (message.Msg == 0x204) return true; /* WM_RBUTTONDOWN */
            if (message.Msg == 0x205) return true; /* WM_RBUTTONUP */
            return false;
        }

        private bool WasNotClickedOnTarget(Control parent, Control target)
        {
            Control clickedOn = parent.GetChildAtPoint(Cursor.Position);
            if (IsNull(clickedOn)) return true;
            if (AreEqual(clickedOn, target)) return false;
            return true;
        }

        private bool AreEqual(Control controlA, Control controlB)
        {
            if (controlA == controlB) return true;
            return false;
        }

        private bool IsNull(Control control)
        {
            if (control == null) return true;
            return false;
        }
    }

Special thanks to my unnamed friend and to "remarkpk11" from the Microsoft Developer Network Frorums.

There are some smaller issues with the code - i dont like that the Messages are hidden from me in the first place and i also would love to get rid of the two global dependencies Cursor and Application. But as far as this question goes i consider it answered.

OTHER TIPS

try axWindowsMediaPlayer1.Ctlenabled = False

EDIT: sorry, this is for vb..

axWindowsMediaPlayer1.Ctlcontrols.stop();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top