public void HandleMessage(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam) { switch (msg) { case (uint)WindowsMessages.WM_LBUTTONDBLCLK: _doubleClick = true; _mwh.RaiseEvent(new RoutedEventArgs(MWDoubleClickEvent)); break; case (uint)WindowsMessages.WM_CONTEXTMENU: { var args = CreateScreenPositionEventArgs(); args.RoutedEvent = MWContextMenuEvent; _mwh.RaiseEvent(args); } break; case (uint)WindowsMessages.WM_LBUTTONUP: { IMediaWindow mediaWindow = _host.GetMediaWindow(); if (mediaWindow != null && mediaWindow.Handle == hWnd && _mwh.MediaEngine.IsMenuOn) { uint mylParam = (uint)lParam; uint x = mylParam & 0x0000FFFF; uint y = mylParam & 0xFFFF0000; y >>= 16; GDI.POINT pt = new GDI.POINT(); pt.x = (int)x; pt.y = (int)y; _mwh.MediaEngine.ActivateDvdMenuButtonAtPosition(pt); } if (!_mwh.MediaEngine.IsMenuOn && !_doubleClick) { _mwh.RaiseEvent(new RoutedEventArgs(MWClickEvent)); } _doubleClick = false; } break; case (uint)WindowsMessages.WM_MOUSEMOVE: if ((uint)lParam != _previousMousePosition) // mouse was actually moved as its position has changed { _previousMousePosition = (uint)lParam; IMediaWindow mediaWindow = _host.GetMediaWindow(); if (mediaWindow != null && mediaWindow.Handle == hWnd && _mwh.MediaEngine.IsMenuOn) { uint mylParam = (uint)lParam; uint x = mylParam & 0x0000FFFF; uint y = mylParam & 0xFFFF0000; y >>= 16; GDI.POINT pt = new GDI.POINT(); pt.x = (int)x; pt.y = (int)y; _mwh.MediaEngine.SelectDvdMenuButtonAtPosition(pt); } if (!_mouseOnWindow) { WindowsManagement.TRACKMOUSEEVENT tme = new WindowsManagement.TRACKMOUSEEVENT(); tme.cbSize = Marshal.SizeOf(tme); tme.dwFlags = WindowsManagement.TME_LEAVE; tme.dwHoverTime = WindowsManagement.HOVER_DEFAULT; tme.hwndTrack = hWnd; WindowsManagement._TrackMouseEvent(ref tme); _mouseOnWindow = true; _mwh.RaiseEvent(new RoutedEventArgs(MWMouseEnterEvent)); } var args = CreateScreenPositionEventArgs(); args.RoutedEvent = MWMouseMoveEvent; _mwh.RaiseEvent(args); } break; case (uint)WindowsMessages.WM_MOUSELEAVE: _mouseOnWindow = false; _mwh.RaiseEvent(new RoutedEventArgs(MWMouseLeaveEvent)); break; case (uint)WindowsMessages.WM_KEYDOWN: var modifiers = Keyboard.Modifiers; var code = wParam.ToInt32(); var key = KeyInterop.KeyFromVirtualKey(code); var handled = HandleKey(key); if (!handled) { _mwh.RaiseEvent(new MWKeyEventArgs(MWKeyDownEvent, key, modifiers)); } break; case (uint)WindowsMessages.WM_MOUSEWHEEL: uint delta = ((uint)wParam) & 0xFFFF0000; delta >>= 16; _mwh.RaiseEvent(new MWMouseWheelEventArgs(MWMouseWheelEvent, (short)delta)); // it's WORD (2 bytes) break; } }
/// <summary> /// Render new media. /// </summary> /// <param name="source">Filename.</param> /// <param name="mediaSourceType">One of the MediaSourceType.</param> /// <returns></returns> public bool BuildGraph(string source, MediaSourceType mediaSourceType) { ResetGraph(); _mediaWindow = _mediaWindowHost.GetMediaWindow(); _mediaWindow.MessageReceived += _mediaWindow_MessageReceived; _filterGraph = FilterGraphBuilder.BuildFilterGraph(source, mediaSourceType, _mediaWindow.Handle, _preferredRenderer, ReportError, delegate(string message) { UserDecisionEventArgs args = new UserDecisionEventArgs(message); OnPartialSuccess(args); return(args.Accept); }); if (_filterGraph != null) { _mediaWindow.SetRendererInterfaces( _filterGraph.Renderer is IVMRWindowless ? ((IVMRWindowless)_filterGraph.Renderer).VMRWindowlessControl : null, _filterGraph.Renderer is IVMR9Windowless ? ((IVMR9Windowless)_filterGraph.Renderer).VMRWindowlessControl : null, _filterGraph.Renderer is IEVR ? ((IEVR)_filterGraph.Renderer).MFVideoDisplayControl : null); _filterGraph.GraphError += (sender, args) => ReportError(args); _filterGraph.PlayBackComplete += (sender, arges) => { if (_repeat) { if (_filterGraph.IsGraphSeekable) { SetCurrentPosition(0); } else // gonna have to think it over! { SetCurrentPosition(0); } } else { StopGraph(); } }; _filterGraph.ErrorAbort += (sender, args) => { ResetGraph(); ReportError(String.Format("{0} {1}", Resources.Resources.mw_error_occured, Resources.Resources.mw_play_aborted)); }; _filterGraph.FailedStreamsAvailable += OnFailedStreamsAvailableInternal; var dvdFilterGraph = _filterGraph as IDvdFilterGraph; if (dvdFilterGraph != null) { dvdFilterGraph.ModifyMenu += (sender, args) => OnModifyMenu(); dvdFilterGraph.DiscEjected += (sender, args) => ResetGraph(); dvdFilterGraph.InitSize += (sender, args) => OnInitSize(false, true); dvdFilterGraph.DvdParentalChange += (sender, args) => args.Raise(this, ref DvdParentalChange); } OnInitSize(true, true); IsMuted = IsMuted; // this resets the volume return(!_autoPlay || ResumeGraph()); } else { CleanUpMediaWindow(); return(false); } }
public void HandleMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam) { switch (Msg) { case (uint)WindowsMessages.WM_LBUTTONDBLCLK: _doubleClick = true; if (_mwh.MWDoubleClick != null) { _mwh.MWDoubleClick(_mwh, EventArgs.Empty); } break; case (uint)WindowsMessages.WM_CONTEXTMENU: if (!_trackingContextMenu) { _trackingContextMenu = true; if (_mwh.MWContextMenu != null) { _mwh.MWContextMenu(Cursor.Position); } } else { _trackingContextMenu = false; } break; case (uint)WindowsMessages.WM_LBUTTONUP: { IMediaWindow mediaWindow = _host.GetMediaWindow(); if (mediaWindow != null && mediaWindow.Handle == hWnd && _mwh._engine.IsMenuOn) { uint mylParam = (uint)lParam; uint x = mylParam & 0x0000FFFF; uint y = mylParam & 0xFFFF0000; y >>= 16; GDI.POINT pt = new GDI.POINT(); pt.x = (int)x; pt.y = (int)y; _mwh._engine.ActivateDvdMenuButtonAtPosition(pt); } if (!_mwh._engine.IsMenuOn && !_doubleClick && _mwh.MWClick != null) { _mwh.MWClick(_mwh, EventArgs.Empty); } _doubleClick = false; } break; case (uint)WindowsMessages.WM_MOUSEMOVE: if ((uint)lParam != _previousMousePosition) // mouse was actually moved as its position has changed { _previousMousePosition = (uint)lParam; IMediaWindow mediaWindow = _host.GetMediaWindow(); if (mediaWindow != null && mediaWindow.Handle == hWnd && _mwh._engine.IsMenuOn) { uint mylParam = (uint)lParam; uint x = mylParam & 0x0000FFFF; uint y = mylParam & 0xFFFF0000; y >>= 16; GDI.POINT pt = new GDI.POINT(); pt.x = (int)x; pt.y = (int)y; _mwh._engine.SelectDvdMenuButtonAtPosition(pt); } if (!_mwh._mouseOnWindow) { WindowsManagement.TRACKMOUSEEVENT tme = new WindowsManagement.TRACKMOUSEEVENT(); tme.cbSize = Marshal.SizeOf(tme); tme.dwFlags = WindowsManagement.TME_LEAVE; tme.dwHoverTime = WindowsManagement.HOVER_DEFAULT; tme.hwndTrack = hWnd; WindowsManagement._TrackMouseEvent(ref tme); _mwh._mouseOnWindow = true; if (_mwh.MWMouseEnter != null) { _mwh.MWMouseEnter(_mwh, EventArgs.Empty); } } if (_mwh.MWMouseMove != null) { _mwh.MWMouseMove(_mwh, EventArgs.Empty); } } break; case (uint)WindowsMessages.WM_MOUSELEAVE: _mwh._mouseOnWindow = false; if (_mwh.MWMouseLeave != null) { _mwh.MWMouseLeave(_mwh, EventArgs.Empty); } break; } }