Click here to Skip to main content
15,892,674 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 204.7K   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;

namespace Microsoft.WindowsAPICodePack.Shell
{
    /// <summary>
    /// A refence to an icon resource 
    /// </summary>
    public struct IconReference
    {
        #region Private members

        private string moduleName;
        private int resourceId;
        private string referencePath;
        static private char[] commaSeparator = new char[] { ',' };

        #endregion

        /// <summary>
        /// Overloaded constructor takes in the module name and resource id for the icon reference.
        /// </summary>
        /// <param name="moduleName">String specifying the name of an executable file, DLL, or icon file</param>
        /// <param name="resourceId">Zero-based index of the icon</param>
        public IconReference(string moduleName, int resourceId)
        {
            if (string.IsNullOrEmpty(moduleName))
                throw new ArgumentNullException("moduleName", "Module name cannot be null or empty string");
            
            this.moduleName = moduleName;
            this.resourceId = resourceId;
            referencePath = moduleName + "," + resourceId;
        }

        /// <summary>
        /// Overloaded constructor takes in the module name and resource id separated by a comma.
        /// </summary>
        /// <param name="refPath">Reference path for the icon consiting of the module name and resource id.</param>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Globalization", "CA1305:SpecifyIFormatProvider", MessageId = "System.Int32.Parse(System.String)", Justification = "We are not currently handling globalization or localization")]
        public IconReference(string refPath)
        {
            if (string.IsNullOrEmpty(refPath))
                throw new ArgumentNullException("refPath", "Reference path cannot be null or empty string");

            string[] refParams = refPath.Split(commaSeparator);

            if (refParams.Length != 2 || string.IsNullOrEmpty(refParams[0]) || string.IsNullOrEmpty(refParams[1]))
                throw new ArgumentException("Reference path is invalid.");

            moduleName = refParams[0];
            resourceId = int.Parse(refParams[1]);

            this.referencePath = refPath;
        }

        /// <summary>
        /// String specifying the name of an executable file, DLL, or icon file
        /// </summary>
        public string ModuleName
        {
            get
            {
                return moduleName;
            }
            set
            {
                if (string.IsNullOrEmpty(value))
                    throw new ArgumentNullException("value", "Module name cannot be null or empty string");

                moduleName = value;
            }
        }

        /// <summary>
        /// Zero-based index of the icon
        /// </summary>
        public int ResourceId
        {
            get
            {
                return resourceId;
            }
            set
            {
                resourceId = value;
            }
        }

        /// <summary>
        /// Reference to a specific icon within a EXE, DLL or icon file.
        /// </summary>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Globalization", "CA1305:SpecifyIFormatProvider", MessageId = "System.Int32.Parse(System.String)", Justification = "We are not currently handling globalization or localization")]
        public string ReferencePath
        {
            get
            {
                return referencePath;
            }
            set
            {
                if (string.IsNullOrEmpty(value))
                    throw new ArgumentNullException("value", "Reference path cannot be null or empty string");

                string[] refParams = value.Split(commaSeparator);

                if (refParams.Length != 2 || string.IsNullOrEmpty(refParams[0]) || string.IsNullOrEmpty(refParams[1]))
                    throw new ArgumentException("Reference path is invalid.");

                ModuleName = refParams[0];
                ResourceId = int.Parse(refParams[1]);

                referencePath = value;
            }
        }

    }

}

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