Click here to Skip to main content
15,895,799 members
Articles / Desktop Programming / Windows Forms

Clipz - A Friendly Introduction to the Windows 7 Taskbar Features

Rate me:
Please Sign up or sign in to vote.
4.91/5 (57 votes)
17 Dec 2009CPOL9 min read 72.3K   1.6K   122  
An overview of the Windows 7 taskbar features, and how to use then in your own applications.
//Copyright (c) Microsoft Corporation.  All rights reserved.

using System;
using System.Runtime.InteropServices;
using Microsoft.WindowsAPICodePack.Controls.WindowsForms;
using Microsoft.WindowsAPICodePack.Controls;

namespace MS.WindowsAPICodePack.Internal
{
    /// <summary>
    /// This provides a connection point container compatible dispatch interface for
    /// hooking into the ExplorerBrowser view.
    /// </summary>
    [ComVisible( true )]
    [ClassInterface( ClassInterfaceType.AutoDual )]
    public class ExplorerBrowserViewEvents
    {
        #region implementation
        private uint viewConnectionPointCookie = 0;
        private object viewDispatch = null;
        private IntPtr nullPtr = IntPtr.Zero;

        private Guid IID_DShellFolderViewEvents = new Guid( ExplorerBrowserIIDGuid.DShellFolderViewEvents );
        private Guid IID_IDispatch = new Guid( ExplorerBrowserIIDGuid.IDispatch );
        private ExplorerBrowser parent = null;
        #endregion

        #region contstruction
        internal ExplorerBrowserViewEvents( ExplorerBrowser parent )
        {
            this.parent = parent;
        }
        #endregion

        #region operations
        internal void ConnectToView( IShellView psv )
        {
            DisconnectFromView( );

            HRESULT hr = psv.GetItemObject(
                SVGIO.SVGIO_BACKGROUND,
                ref IID_IDispatch,
                out viewDispatch );

            if( hr == HRESULT.S_OK )
            {
                hr = ExplorerBrowserNativeMethods.ConnectToConnectionPoint(
                    this,
                    ref IID_DShellFolderViewEvents,
                    true,
                    viewDispatch,
                    ref viewConnectionPointCookie,
                    ref nullPtr );

                if( hr != HRESULT.S_OK )
                {
                    Marshal.ReleaseComObject( viewDispatch );
                }
            }
        }

        internal void DisconnectFromView( )
        {
            if( viewDispatch != null )
            {
                ExplorerBrowserNativeMethods.ConnectToConnectionPoint(
                    IntPtr.Zero,
                    ref IID_DShellFolderViewEvents,
                    false,
                    viewDispatch,
                    ref viewConnectionPointCookie,
                    ref nullPtr );

                Marshal.ReleaseComObject( viewDispatch );
                viewDispatch = null;
                viewConnectionPointCookie = 0;
            }
        }
        #endregion

        #region IDispatch events
        // These need to be public to be accessible via AutoDual reflection

        /// <summary>
        /// The view selection has changed
        /// </summary>
        [DispId( ExplorerBrowserViewDispatchIds.SelectionChanged )]
        public void ViewSelectionChanged( )
        {
            parent.FireSelectionChanged( );
        }

        /// <summary>
        /// The contents of the view have changed
        /// </summary>
        [DispId( ExplorerBrowserViewDispatchIds.ContentsChanged )]
        public void ViewContentsChanged( )
        {
            parent.FireContentChanged( );
        }

        /// <summary>
        /// The enumeration of files in the view is complete
        /// </summary>
        [DispId( ExplorerBrowserViewDispatchIds.FileListEnumDone )]
        public void ViewFileListEnumDone( )
        {
            parent.FireContentEnumerationComplete( );
        }

        /// <summary>
        /// The selected item in the view has changed (not the same as the selection has changed)
        /// </summary>
        [DispId( ExplorerBrowserViewDispatchIds.SelectedItemChanged )]
        public void ViewSelectedItemChanged( )
        {
            parent.FireSelectedItemChanged( );
        }
        #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)


Written By
Web Developer PageLabs
United States United States
I'm the founder of PageLabs, a web-based performance and SEO optimization site.

Give your site a boost in performance, even take a free speed test!

http://www.pagelabs.com

Comments and Discussions