如何阻止 AxWindowsMediaPlayer 接受 C# 中的任何用户命令

发布于 2024-12-25 09:38:05 字数 478 浏览 2 评论 0原文

在我的演示代码中,嵌入式 Windows 媒体播放器开始加载并播放视频。播放器不显示任何控件,所有其他选项均为默认选项。到目前为止这有效。

不起作用的是并非所有用户交互都被停止。例如,可以通过双击将模式更改为全屏,也可以通过右键单击获得完整的上下文。

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

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

如何将播放器与用户隔离并仅通过代码控制播放器?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

简美 2025-01-01 09:38:05

一个朋友刚刚帮我解决了这个问题。

禁用上下文菜单相当容易

axWindowsMediaPlayer1.enableContextMenu = false;

禁用双击需要消息过滤器 - 网上已经有解决方案

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

我重写了我的示例,现在使用此代码:

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;
        }
    }

特别感谢我的匿名朋友和来自 Microsoft 开发者网络 Frorums 的“remarkpk11”。

代码存在一些较小的问题 - 我不喜欢消息一开始就对我隐藏,我也希望摆脱两个全局依赖项 Cursor 和 Application。但就这个问题而言,我认为它已经得到解答。

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.

掌心的温暖 2025-01-01 09:38:05

尝试 axWindowsMediaPlayer1.Ctlenabled = False

编辑:抱歉,这是针对 vb 的。

try axWindowsMediaPlayer1.Ctlenabled = False

EDIT: sorry, this is for vb..

全部不再 2025-01-01 09:38:05
axWindowsMediaPlayer1.Ctlcontrols.stop();
axWindowsMediaPlayer1.Ctlcontrols.stop();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文