Click here to Skip to main content
Click here to Skip to main content
 
Add your own
alternative version
Go to top

DSGraphEdit: A Reasonable Facsimile of Microsoft's GraphEdit in .NET

, 19 Dec 2007
A library for adding DirectShow GraphEdit-like abilities to .NET applications.
dsgrapheditdemo.zip
WeifenLuo.WinFormsUI.Docking.dll
DaggerLib.dll
DaggerLib.DSGraphEdit.dll
DaggerLib.UI.Windows.dll
DirectShowLib-2005.dll
DSGraphEdit.exe
MediaFoundation.dll
dsgrapheditsrc.zip
DSGraphEdit
bin
Release
DSIcon.ico
Properties
Settings.settings
Referenced Libs
WeifenLuo.WinFormsUI.Docking.dll
RemoteGraphTile.jpg
DaggerLib
bin
Release
Core
Interfaces
Properties
SetGeneric
UI
DaggerLib.DSGraphEdit
DMOParameterControls
DSFilterTreeView
DSGraphEditControls
lib
Properties
ReferencedLibs
DirectShowLib-2005.dll
MediaFoundation.dll
DaggerLib.UI.Windows
AStar
bin
Debug
DaggerPropertyGrid
PropertyGridEx
Properties
using System;
using System.ComponentModel;
using System.Windows.Forms;
using System.Collections.Generic;
using System.Text;
using DirectShowLib;

namespace DaggerLib.DSGraphEdit
{
    [ToolboxItem(false)]
    public class DSFilterTreeView : TreeView
    {
        private ContextMenuStrip contextMenuStrip1;
        private System.ComponentModel.IContainer components;
        private ToolStripMenuItem _refreshFiltersContextMenuItem;
    
        public DSFilterTreeView()
        {
            InitializeComponent();
        }

        #region InitializeComponent

        private void InitializeComponent()
        {
            this.components = new System.ComponentModel.Container();
            this.contextMenuStrip1 = new System.Windows.Forms.ContextMenuStrip(this.components);
            this._refreshFiltersContextMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.contextMenuStrip1.SuspendLayout();
            this.SuspendLayout();
            // 
            // contextMenuStrip1
            // 
            this.contextMenuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this._refreshFiltersContextMenuItem});
            this.contextMenuStrip1.Name = "contextMenuStrip1";
            this.contextMenuStrip1.Size = new System.Drawing.Size(145, 26);
            // 
            // _refreshFiltersContextMenuItem
            // 
            this._refreshFiltersContextMenuItem.Name = "_refreshFiltersContextMenuItem";
            this._refreshFiltersContextMenuItem.Size = new System.Drawing.Size(144, 22);
            this._refreshFiltersContextMenuItem.Text = "Refresh Filters";
            this._refreshFiltersContextMenuItem.Click += new System.EventHandler(this._refreshFiltersContextMenuItem_Click);
            // 
            // DSFilterTreeView
            // 
            this.ContextMenuStrip = this.contextMenuStrip1;
            this.LineColor = System.Drawing.Color.Black;
            this.contextMenuStrip1.ResumeLayout(false);
            this.ResumeLayout(false);

        }

        #endregion

        protected override void OnItemDrag(ItemDragEventArgs e)
        {
            //only allow dragging of child nodes
            if ((e.Item as TreeNode).Level > 0)
            {
                DoDragDrop(e.Item, DragDropEffects.Move);
            }
            base.OnItemDrag(e);
        }

        public void SyncFilters()
        {
            // get a list of all standard Direct Show Filter Categories
            List<DsDevice> categories = new List<DsDevice>(DirectShowLib.DsDevice.GetDevicesOfCat(FilterCategory.ActiveMovieCategories));

            // find tree nodes that haven't been created for a category yet
            foreach (DsDevice dev in categories)
            {
                if (GetParentNodeByName(dev.Name) == null)
                {
                    // create the IDSFilterCollection for this category
                    TreeNode tn = new TreeNode(dev.Name);
                    tn.Tag = new StandardFilterCategory(dev);
                    Nodes.Add(tn);
                }
            }

            this.BeginUpdate();
            foreach (TreeNode tn in Nodes)
            {
                IDSFilterCollection categoryCollection = (IDSFilterCollection)tn.Tag;
                // sync the filters in the filter collection with the tree view
                categoryCollection.SyncTreeNodes(tn.Nodes);
            }
            Sort();
            this.EndUpdate();
        }

        public void AddCategory(IDSFilterCollection categoryCollection)
        {
            // create a parent node for the filter collection
            TreeNode tn = new TreeNode(categoryCollection.CategoryName);
            tn.Tag = categoryCollection;
            Nodes.Add(tn);
        }

        public TreeNode GetParentNodeByName(string name)
        {
            foreach (TreeNode tn in Nodes)
            {
                if (tn.Text == name) return tn;
            }

            return null;
        }

        public static DSFilterTreeViewNode GetTreeNodeByDevicePath(string path,TreeNodeCollection collection)
        {
            foreach (DSFilterTreeViewNode tn in collection)
            {
                if (tn.DevicePath == path) return tn;
            }

            return null;
        }

        public static DSFilterTreeViewNode GetTreeNodeByGuid(Guid guid,TreeNodeCollection collection)
        {
            foreach (DSFilterTreeViewNode tn in collection)
            {
                if (tn.ClassGuid == guid) return tn;
            }

            return null;
        }

        private void _refreshFiltersContextMenuItem_Click(object sender, EventArgs e)
        {
            SyncFilters();
        }
    }
}

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

JohnnyLocust
Software Developer (Senior) Haivision Network Video
United States United States
AKA Rich Insley.
 
I have over 25 years experience in programming, and I'm completely self taught. (Except for one year at California State University Fresno where I had to learn the God awful language Miranda (http://miranda.org.uk/). I've spent 10 years as a Paratrooper in the US Army during the Clinton Administration.
Follow on   LinkedIn

| Advertise | Privacy | Mobile
Web04 | 2.8.140916.1 | Last Updated 20 Dec 2007
Article Copyright 2007 by JohnnyLocust
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid