Click here to Skip to main content
13,799,800 members
Click here to Skip to main content

Stats

722.5K views
29.8K downloads
281 bookmarked
Posted 14 Sep 2010
Licenced CPOL

PVS.AVPlayer - MCI Audio and Video Library

, 7 Aug 2018
Windows Media Control Interface (MCI) library with many added features
PVS.AVPlayer
PVS.AVPlayer .NET 2.0
PVS.AVPlayer.XML
PVS.AVPlayer .NET 3.0
PVS.AVPlayer.XML
PVS.AVPlayer .NET 3.5
PVS.AVPlayer.XML
PVS.AVPlayer .NET 4.0
PVS.AVPlayer.XML
PVS.AVPlayer .NET 4.5
PVS.AVPlayer .NET 4.5.1
PVS.AVPlayer.XML
PVS.AVPlayer .NET 4.5.2
PVS.AVPlayer.XML
PVS.AVPlayer.XML
PVS.AVPlayer .NET 4.6
PVS.AVPlayer.XML
PVS.AVPlayer.dll
PVS.AVPlayer.XML
PVS.AVPlayer.dll
PVS.AVPlayer.XML
PVS.AVPlayer.dll
PVS.AVPlayer.XML
PVS.AVPlayer.dll
PVS.AVPlayer.XML
PVS.AVPlayer.dll
PVS.AVPlayer.XML
PVS.AVPlayer.dll
PVS.AVPlayer.XML
PVS.AVPlayer.dll
PVS.AVPlayer.XML
PVS.AVPlayer .NET 4.6.1
PVS.AVPlayer.dll
PVS.AVPlayer.XML
PVS.AVPlayer .NET 4.6.2
PVS.AVPlayer.dll
PVS.AVPlayer.XML
PVS.AVPlayer.dll
PVS.AVPlayer.XML
PVS.AVPlayer .NET 4.7
PVS.AVPlayer .NET 4.7.1
PVS.AVPlayer.dll
PVS.AVPlayer.XML
PVS.AVPlayer .NET 4.7.2
PVS.AVPlayer.dll
PVS.AVPlayer.XML
PVS.AVPlayer.dll
PVS.AVPlayer.XML
PVS.AVPlayer All Source Code
AVPlayerExample
AVPlayerExample
AVPlayerExample.csproj.user
bin
Debug
PVS.AVPlayer.XML
Release
Dialogs
Display Overlays
obj
Debug
Release
x86
Debug
Release
Properties
Resources
Crystal Italic1.ttf
WingDings3a.ttf
Voice Recorder
FolderView
FolderView
bin
Debug
PVS.AVPlayer.XML
Release
FolderView.csproj.user
obj
Release
x86
Debug
Release
Properties
Resources
Crystal Italic1.ttf
PVS.AVPlayer
AVPlayerExample.csproj.user
PVS.AVPlayer.dll
PVS.AVPlayer.XML
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
PVS.AVPlayer.XML
Custom Items
FolderView.csproj.user
Debug
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
PVS.AVPlayer.XML
Release
obj
Debug
Release
Properties
How To (VB.NET)
PVSAVPlayerHowToVB
bin
Debug
PVS.AVPlayer.dll
PVS.AVPlayer.XML
Release
My Project
Application.myapp
obj
Debug
Release
PVSAVPlayerHowTo.vbproj.user
PVS.AVPlayer Examples
AVPlayerExample.ex_
FolderView.ex_
AVPlayerExample.exe
FolderView.exe
PVS.AVPlayer.dll
#region Usings

using System;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;

#endregion

namespace FolderView
{
    // *********************************************

    // A custom drawn slider can be created using the standard .NET TrackBar control if you draw the trackbar
    // items (track, thumb) yourself (ControlStyles.UserPaint) inside the same 'space' (size and location) as
    // the original items (as shown below).

    // Actually, you can draw whatever you like as long as you keep the thumb inside it's original size and location
    // (see below; because of the trackbar's redraw with 'smart clipping'). And even this can be (partially) ignored
    // if you use CreateGraphics() (instead of e.Grahics - as with CustomSlider2) to draw.

    // The track (channel) is always at a fixed position and size (given the orientation, width and tickstyle);
    // the thumb (slider) size is fixed too and it's position can be found with 'SendMessage' (please see below - dll import).
    // The height of the entire control (horizontal bar) has to be at least 26 pixels to avoid 'drawing problems'.

    // --------

    // The size and location of the trackbar items can be found with 'SendMessage' (TBM_GETTHUMBRECT and TBM_GETCHANNELRECT):
    // Original size and location:

    // Horizontal TrackBar with TickStyle None or BottomRight:
    // Thumb: X=(variable), Y=2, Width=11, Height=19
    // Track: X=8, Y=8, Width=ControlWidth-16, Height=4

    // Horizontal TrackBar with TickStyle TopLeft:
    // Thumb: X=(variable), Y=10, Width=11, Height=19
    // Track: X=8, Y=18, Width=ControlWidth-16, Height=4

    // Horizontal TrackBar with TickStyle Both:
    // Thumb: X=(variable), Y=10, Width=11, Height=22
    // Track: X=8, Y=19, Width=ControlWidth-16, Height=4

    // --------

    // Vertical TrackBar with TickStyle None or BottomRight:
    // Thumb: X=2, Y=(variable), Width=19, Height=11
    // Track: X=8, Y=8, Width=4, Height=ControlHeight-16

    // Vertical TrackBar with TickStyle TopLeft:
    // Thumb: X=10, Y=(variable), Width=19, Height=11
    // Track: X=18, Y=8, Width=4, Height=ControlHeight-16

    // Vertical TrackBar with TickStyle Both:
    // Thumb: X=10, Y=(variable), Width=22, Height=11
    // Track: X=19, Y=8, Width=4, Height=ControlHeight-16

    // --------

    // Instead of drawing all the items yourself, you can also make use of .Net controls or the TrackBarRenderer Class:
    // http://msdn.microsoft.com/en-us/library/6bzct57b%28v=vs.90%29.aspx

    // --------

    // There are a few things missing from these examples (like the 'state' (appearance) of the thumb, disabled control colors
    // and vertical orientation) but these can easily be added. And you could add support for the designer too if you like.
    // But if you're using a 'fixed type' trackbar (like the ones used here) there's no need for that.

    // *********************************************
    
    // Slider used with ItemView
    class CustomSlider1 : TrackBar
    {
        // ********************************************* Fields

        #region Fields

        Point                   _trackStartPoint; // using a horizontal line as track
        Point                   _trackEndPoint;
        SafeNativeMethods.RECT  _thumbRECT;
        Rectangle               _thumbRect;
        LinearGradientBrush     _brush;

        #endregion

        // ********************************************* Main

        #region Main

        public CustomSlider1()
        {
            SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint, true);
            AutoSize = false;

            _trackStartPoint = new Point(8, 8);
            _trackEndPoint = new Point(Width - 8, 8);

            _thumbRECT = new SafeNativeMethods.RECT();
            _thumbRect = new Rectangle(0, 6, 11, 5);

            _brush = new LinearGradientBrush(_thumbRect, Color.DarkGoldenrod, Color.Goldenrod, LinearGradientMode.Vertical);
            _brush.SetBlendTriangularShape(0.5F);
        }

        protected override void OnSizeChanged(EventArgs e)
        {
            _trackEndPoint.X = Width - 8;
            base.OnSizeChanged(e);
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                _brush.Dispose();
            }
            base.Dispose(disposing);
        }

        #endregion

        // ********************************************* OnPaint

        #region OnPaint

        protected override void OnPaint(PaintEventArgs e)
        {
            // draw track
            e.Graphics.DrawLine(Pens.DimGray, _trackStartPoint, _trackEndPoint);

            // draw thumb
            SafeNativeMethods.SendMessage(Handle, SafeNativeMethods.TBM_GETTHUMBRECT, IntPtr.Zero, ref _thumbRECT);
            _thumbRect.X = _thumbRECT.left;
            e.Graphics.FillEllipse(_brush, _thumbRect);
        }

        #endregion
    }

    // Slider used with DetailView
    class CustomSlider2 : TrackBar
    {
        // ********************************************* Fields

        #region Fields

        Rectangle               _trackRect;
        Rectangle               _tempRect; // split track area before and after thumb

        SafeNativeMethods.RECT  _thumbRECT;
        Rectangle               _thumbBorderRect;
        Rectangle               _thumbFillRect; // to reduce flicker
        Rectangle               _thumbEraseRect; // to reduce flicker - border right/bottom line outside rect

        Region                  _eraseRegion; // to reduce flicker
        SolidBrush              _eraseBrush;

        LinearGradientBrush     _thumbBrush;
        LinearGradientBrush     _trackBrush1;
        LinearGradientBrush     _trackBrush2;

        #endregion

        // ********************************************* Main

        #region Main

        public CustomSlider2()
        {
            SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.Opaque, true);
            base.BackColor = Color.Black;
            AutoSize = false;

            // background
            _eraseRegion = new Region(ClientRectangle);
            _eraseBrush = new SolidBrush(Color.Black); // default backcolor

            // track
            _trackRect = new Rectangle(8, 8, Width - 16, 4);
            _tempRect = new Rectangle(8, 8, Width - 16, 4);
            _trackBrush1 = new LinearGradientBrush(_trackRect, Color.FromArgb(96, 96, 96), Color.Black, LinearGradientMode.Vertical);
            _trackBrush1.SetBlendTriangularShape(0.5F);
            _trackBrush2 = new LinearGradientBrush(_trackRect, Color.FromArgb(48, 48, 48), Color.Black, LinearGradientMode.Vertical);
            _trackBrush2.SetBlendTriangularShape(0.5F);

            // thumb
            _thumbRECT = new SafeNativeMethods.RECT();
            _thumbBorderRect = new Rectangle(0, 2, 9, 14);
            _thumbEraseRect = new Rectangle(0, 2, 10, 15);
            _thumbFillRect = new Rectangle(0, 3, 8, 13);
            _thumbBrush = new LinearGradientBrush(_thumbBorderRect, Color.FromArgb(132, 132, 132), Color.Black, LinearGradientMode.Vertical);
            _thumbBrush.SetBlendTriangularShape(0.5F);
        }

        [DefaultValue(typeof(Color), "Black")]
        public override Color BackColor
        {
            get
            {
                return base.BackColor;
            }
            set
            {
                base.BackColor = value;
                _eraseBrush.Color = value;
            }
        }

        protected override void OnSizeChanged(EventArgs e)
        {
            _trackRect.Width = Width - 16;
            base.OnSizeChanged(e);
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                _eraseRegion.Dispose();
                _eraseBrush.Dispose();

                _thumbBrush.Dispose();
                _trackBrush1.Dispose();
                _trackBrush2.Dispose();
            }

            base.Dispose(disposing);
        }

        #endregion

        // ********************************************* OnPaint

        #region OnPaint

        protected override void OnPaint(PaintEventArgs e)
        {
            // using 'new' graphics (instead of clipped e.Graphics) to avoid problems with 'smart clipping' (when fast moving
            // the thumb to another position) because the track's appearance is not everywhere the same (before and after the thumb).
            Graphics g = CreateGraphics();

            // get the thumb position first - also used with erase and draw track
            SafeNativeMethods.SendMessage(Handle, SafeNativeMethods.TBM_GETTHUMBRECT, IntPtr.Zero, ref _thumbRECT);
            _thumbBorderRect.X = _thumbEraseRect.X = _thumbRECT.left;
            _thumbFillRect.X = _thumbRECT.left + 1;

            // erase background
            _eraseRegion.MakeEmpty();
            _eraseRegion.Union(ClientRectangle);
            _eraseRegion.Exclude(_trackRect);
            _eraseRegion.Exclude(_thumbEraseRect);
            g.FillRegion(_eraseBrush, _eraseRegion);
            // with this trackbar (all items within original bounds) we could have used:
            //e.Graphics.FillRectangle(eraseBrush, this.ClientRectangle);

            // draw track - different fill color before and after thumb position
            // before thumb
            _tempRect.X = _trackRect.X;
            _tempRect.Width = _thumbBorderRect.X - _trackRect.X;
            g.FillRectangle(_trackBrush1, _tempRect);
            // after thumb
            _tempRect.X = _thumbBorderRect.X + _thumbBorderRect.Width;
            _tempRect.Width = _trackRect.Width - _thumbBorderRect.X;
            g.FillRectangle(_trackBrush2, _tempRect);

            // draw thumb
            g.DrawRectangle(Pens.DimGray, _thumbBorderRect);
            g.FillRectangle(_thumbBrush, _thumbFillRect);

            g.Dispose();
        }

        #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 | Cookies | Terms of Use | Mobile
Web04 | 2.8.181214.1 | Last Updated 7 Aug 2018
Article Copyright 2010 by Peter Vegter
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid