Axwindows media player dectect keydown in full screen mode

馋奶兔 提交于 2019-12-24 01:53:11

问题


I have ax windows media player in my windows forms application. When the user double clicks on it, it becomes full screen.

PROBLEM: I want the user to be able to go back to normal screen when he presses the "escape key". I have put a keydown event on the ax media player. This key down event works when in normal mode, but fails when the media player is made full screen.

 WMPLarge.KeyDownEvent += new AxWMPLib._WMPOCXEvents_KeyDownEventHandler(Form1_KeyDown);

 private void Form1_KeyDown(object sender, AxWMPLib._WMPOCXEvents_KeyDownEvent e)
    {
        if (e.nKeyCode == 27)
        {
            MessageBox.Show("");
            WMPLarge.fullScreen = false;
            WMPSmall.fullScreen = false;
        }
    }

How can I achieve this ?


回答1:


Here is one code snippet I used, I hope that helps.

public partial class Form16 : Form,IMessageFilter
{
    public Form16()
    {
        InitializeComponent();
    }

    private void Form16_Load(object sender, EventArgs e)
    {
        this.axWindowsMediaPlayer1.URL = @"D:\MyVideo\myfile.wmv";
        Application.AddMessageFilter(this);
    }

    private void Form16_FormClosing(object sender, FormClosingEventArgs e)
    {
        Application.RemoveMessageFilter(this);
    }

    #region IMessageFilter Members
    private const UInt32 WM_KEYDOWN = 0x0100;
    public bool PreFilterMessage(ref Message m)
    {
        if (m.Msg == WM_KEYDOWN)
        {
            Keys keyCode = (Keys)(int)m.WParam & Keys.KeyCode;
            if (keyCode == Keys.Escape)
            {
                this.axWindowsMediaPlayer1.fullScreen = false;
            }
            return true;
        }
        return false;
    }
    #endregion
}


来源:https://stackoverflow.com/questions/19249307/axwindows-media-player-dectect-keydown-in-full-screen-mode

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!