Search code examples
c#.netwindows-media-playerwmp

WMP: unable to control/handle events when in fullscreen


I have added a Windows Media control to my form and have been able to use it perfectly except when it is in the fullscreen state. It seems that I am unable to manipulate any aspects of the control through key events within my application. My current goal is to handle 'esc' key down to exit out of full screen. I can do more from there on.

If you have any idea please let me know!

Thanks, Kevin


Solution

  • I once found this code somewhere and worked pretty well, but don't remember where i got it from.

        public partial class WMForm : Form,IMessageFilter
    
    {
    
        public WMForm()
    
        {
    
            InitializeComponent();
    
        }
    
    
    
        private void WMForm_Load(object sender, EventArgs e)
    
        {
    
            this.MyWindowsMediaPlayer.URL = @"YourFilePath/Url";
    
            Application.AddMessageFilter(this);
    
        }
    
    
    
        private void WMForm_FormClosing(object sender, FormClosingEventArgs e)
    
        {
    
            Application.RemoveMessageFilter(this);
    
        }
    
    
    
        #region IMessageFilter
    
        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.MyWindowsMediaPlayer.fullScreen = false;
    
                }
    
                return true;
    
            }
    
            return false;
    
        }
    
        #endregion
    
    }