Click here to Skip to main content
15,886,199 members
Articles / Desktop Programming / Windows Forms

Task Manager

Rate me:
Please Sign up or sign in to vote.
4.90/5 (105 votes)
1 Jan 2010CPOL4 min read 203.9K   21K   229  
Manage your daily tasks and To-Do list using some exciting features of Windows 7.
//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
Chief Technology Officer
Pakistan Pakistan
Passion and positive dedication is essential part of success. I believe on hardworking and sharing knowledge with others. I always try to be a better than I am and think positive for positive result.

My Blogs

My Linked-In Profile

Comments and Discussions