Click here to Skip to main content
13,552,926 members
Click here to Skip to main content

Stats

640.8K views
28.4K downloads
270 bookmarked
Posted 14 Sep 2010
Licenced CPOL

PVS.AVPlayer - MCI Audio and Video Library

, 16 Apr 2018
Windows Media Control Interface (MCI) library with many added features
PVS.AVPlayer
PVS.AVPlayer .NET 2.0
PVS.AVPlayer .NET 3.0
PVS.AVPlayer .NET 3.5
PVS.AVPlayer .NET 4.0
PVS.AVPlayer .NET 4.5
PVS.AVPlayer .NET 4.5.1
PVS.AVPlayer .NET 4.5.2
PVS.AVPlayer .NET 4.6
PVS.AVPlayer.dll
PVS.AVPlayer.dll
PVS.AVPlayer.dll
PVS.AVPlayer.dll
PVS.AVPlayer.dll
PVS.AVPlayer.dll
PVS.AVPlayer.dll
PVS.AVPlayer .NET 4.6.1
PVS.AVPlayer.dll
PVS.AVPlayer .NET 4.6.2
PVS.AVPlayer.dll
PVS.AVPlayer.dll
PVS.AVPlayer .NET 4.7
PVS.AVPlayer .NET 4.7.1
PVS.AVPlayer.dll
PVS.AVPlayer .NET 4.7.2
PVS.AVPlayer.dll
PVS.AVPlayer.dll
PVS.AVPlayer All Source Code
AVPlayerExample
AVPlayerExample
AVPlayerExample.csproj.user
bin
Debug
Release
Dialogs
Display Overlays
obj
Debug
Release
x86
Debug
Release
Properties
Resources
Crystal Italic1.ttf
WingDings3a.ttf
Voice Recorder
FolderView
FolderView
bin
Debug
Release
FolderView.csproj.user
obj
Release
x86
Debug
Release
Properties
Resources
Crystal Italic1.ttf
PVS.AVPlayer
AVPlayerExample.csproj.user
PVS.AVPlayer.dll
Custom Items
Native Methods
Bob.png
Crystal Italic1.ttf
Dial Green 2.png
Dial Green 4.png
Dial Green.png
Dial Red 2.png
Dial Red.png
media7.ico
media7a.ico
Media8.ico
Media8a.ico
VU Meter.png
WingDings3a.ttf
Sound Recorder
Various
About Dialog
PVS.AVPlayer.dll
Custom Items
FolderView.csproj.user
Bob.png
Crystal Italic1.ttf
media7a.ico
media7b.ico
Media8a.ico
Media8b.ico
Subtitles Overlay
Various
How To (C#)
PVSAVPlayerHowTo
bin
Debug
PVS.AVPlayer.dll
Release
Properties
How To (VB.NET)
PVSAVPlayerHowToVB
ApplicationEvents.v_b
bin
Debug
PVS.AVPlayer.dll
Release
Form1.Designer.v_b
Form1.v_b
My Project
app.manifest
Application.Designer.v_b
Application.myapp
AssemblyInfo.v_b
Resources.Designer.v_b
Settings.Designer.v_b
Overlay.Designer.v_b
Overlay.v_b
PVSAVPlayerHowTo.vbproj.user
PVS.AVPlayer Examples
AVPlayerExample.ex_
FolderView.ex_
AVPlayerExample.exe
FolderView.exe
PVS.AVPlayer.dll
#region Usings

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Security.Permissions;
using System.Windows.Forms;

#endregion

namespace AVPlayerExample
{
    public partial class MainWindow
    {
        // Automatically hide (after not having moved for a few seconds) and unhide (when moved/clicked) the mouse cursor when playing media.
        // A MessageFilter is used to detect mouse events.

        // For use with AVPlayerExample - for (general) use with other apps this code has to be changed/extended a little bit
        // - can also be easily changed to work with player displays instead of full forms

        #region Mouse Hide Fields

        private Timer           _mouseHideTimer;
        private DateTime        _mouseHideMoved;
        private Point           _mouseHideOldPosition;
        private bool            _mouseHideActive;
        private int             _mouseHideActiveCount;
        private bool            _mouseHideDisabled;
        private int             _mouseHideDisabledCount;
        private bool            _mouseHideHidden;
        private MouseHideFilter _mouseHideFilter;
        private List<Form>      _registeredForms;

        #endregion

        // *********

        #region Register Forms - Subscribe and unsubscribe Forms

        internal void RegisterMouseHideForm(Form form)
        {
            if (_registeredForms == null) _registeredForms = new List<Form>(8);
            if (!_registeredForms.Contains(form)) _registeredForms.Add(form);
        }

        internal void UnregisterMouseHideForm(Form form)
        {
            if (_registeredForms != null) _registeredForms.Remove(form);
        }

        #endregion

        // *********

        #region Mouse Hide activating and de-activating

        // It's assumed that there's at least 1 registered form - TODO suspend start if no registered forms
        internal void MouseHideStart()
        {
            if (Prefs.AutoHideCursor && !_mouseHideActive)
            {
                if (_mouseHideTimer == null)
                {
                    _mouseHideMoved = new DateTime();

                    _mouseHideTimer = new Timer();
                    _mouseHideTimer.Interval = Prefs.AutoHideCursorSeconds * 1000;
                    _mouseHideTimer.Tick += MouseHideTimer_Tick;

                    _mouseHideFilter = new MouseHideFilter();
                    _mouseHideFilter.Client = this;
                }

                _mouseHideMoved = DateTime.Now;
                _mouseHideTimer.Start();
                Application.AddMessageFilter(_mouseHideFilter);

                _mouseHideActiveCount++;
                _mouseHideActive = true;
            }
        }

        internal void MouseHideStop(bool dispose)
        {
            if ((--_mouseHideActiveCount <= 0 || dispose) && _mouseHideActive)
            {
                _mouseHideTimer.Stop();
                Application.RemoveMessageFilter(_mouseHideFilter);
                _mouseHideActive = false;

                if (_mouseHideHidden)
                {
                    Cursor.Show();
                    _mouseHideHidden = false;
                }
                _mouseHideActiveCount = 0;
            }

            //dispose = true is called from Dispose() (when quiting application) of MainWindow
            if (dispose && _mouseHideTimer != null)
            {
                _mouseHideTimer.Dispose();
                _mouseHideTimer = null;
                _mouseHideFilter.Client = null;
                _mouseHideFilter = null;
                _registeredForms.Clear();
                _registeredForms = null;
            }
        }

        #endregion

        #region Mouse Hide timer (hide) and mouse move and action (show) eventhandlers

        // strange: bottom scrolling text of message overlay influences ActiveForm value or mouse event?
        private void MouseHideTimer_Tick(object sender, EventArgs e)
        {
            if (_mouseHideDisabled) return;

            if (!_mouseHideHidden && Form.ActiveForm != null)
            {
                if ((DateTime.Now - _mouseHideMoved).TotalSeconds >= Prefs.AutoHideCursorSeconds)
                {
                    if (_registeredForms.Contains(Form.ActiveForm))
                    {
                        _mouseHideTimer.Stop();
                        _mouseHideOldPosition = Cursor.Position;
                        Cursor.Hide();
                        HideSliderPreviewByTimer();
                        _mouseHideHidden = true;
                    }
                }
            }
        }

        private void MouseHideMove()
        {
            _mouseHideMoved = DateTime.Now;
            if (_mouseHideHidden)
            {
                Point _mouseHideNewPosition = Cursor.Position;
                if (Math.Abs(_mouseHideNewPosition.X - _mouseHideOldPosition.X) >= 2 || Math.Abs(_mouseHideNewPosition.Y - _mouseHideOldPosition.Y) >= 2)
                {
                    Cursor.Show();
                    _mouseHideHidden = false;
                    _mouseHideTimer.Start();
                }
                else _mouseHideOldPosition = _mouseHideNewPosition;
            }
        }

        private void MouseHideAction()
        {
            _mouseHideMoved = DateTime.Now;
            if (_mouseHideHidden)
            {
                Cursor.Show();
                _mouseHideHidden = false;
                _mouseHideTimer.Start();
            }
        }

        #endregion

        // *********

        #region Temporarily disable MouseHide by contextmenus

        // Temporarily disable hiding of the mouse cursor (should be done for all pop-up menus)
        private void ContextMenu_Opening(object sender, CancelEventArgs e)
        {
            _mouseHideDisabled = true;
            _mouseHideDisabledCount++;
        }

        private void ContextMenu_Closing(object sender, ToolStripDropDownClosingEventArgs e)
        {
            if (--_mouseHideDisabledCount <= 0)
            {
                _mouseHideDisabled = false;
                _mouseHideDisabledCount = 0;
            }
        }

        #endregion

        // *********

        #region Mouse Hide MessageFilter

        public class MouseHideFilter : IMessageFilter
        {
            internal MainWindow Client;

            [SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.UnmanagedCode)]
            public bool PreFilterMessage(ref Message m)
            {
                if (m.Msg == 0x0200) Client.MouseHideMove(); // WM_MOUSEMOVE
                else if (m.Msg > 0x0200 && m.Msg <= 0x020A) Client.MouseHideAction();
                return false;
            }
        }

        #endregion
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Peter Vegter
United States United States
No Biography provided

You may also be interested in...

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02-2016 | 2.8.180515.1 | Last Updated 16 Apr 2018
Article Copyright 2010 by Peter Vegter
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid