Click here to Skip to main content
15,895,808 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.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.Text;
using System.Windows;
using System.Windows.Forms;

namespace Microsoft.WindowsAPICodePack.Taskbar
{
    internal sealed class TabbedThumbnailProxyWindow : Form, IDisposable
    {
        private IntPtr proxyingFor;

        internal TabbedThumbnailProxyWindow(TabbedThumbnail preview)
        {
            TabbedThumbnail = preview;

            if (preview.WindowHandle != IntPtr.Zero)
            {
                proxyingFor = preview.WindowHandle;
                Size = new System.Drawing.Size(1, 1);

                // Try to get the window text so we can use it on the tabbed thumbnail as well
                StringBuilder text = new StringBuilder(256);
                TabbedThumbnailNativeMethods.GetWindowText(proxyingFor, text, text.Capacity);
                Text = text.ToString();
                
                // If we get a valid title from the GetWindowText method,
                // and also if the user hasn't set any title on the preview object,
                // then update the preview's title with what we get from GetWindowTitle
                if(!string.IsNullOrEmpty(Text) && string.IsNullOrEmpty(preview.Title))
                    preview.Title = Text;
            }
            else if (preview.WindowsControl != null)
            {
                proxyingFor = IntPtr.Zero;
                WindowsControl = preview.WindowsControl;
                Size = new System.Drawing.Size(1, 1);
                // Since we can't get the text/caption for a UIElement, not setting this.Text here.

            }
        }

        internal TabbedThumbnail TabbedThumbnail
        {
            get;
            private set;
        }

        internal IntPtr RealWindow
        {
            get { return proxyingFor; }
        }

        internal UIElement WindowsControl
        {
            get;
            private set;
        }

        internal IntPtr WindowToTellTaskbarAbout
        {
            get { return this.Handle; }
        }

        protected override void WndProc(ref Message m)
        {
            bool handled = false;

            if(this.TabbedThumbnail != null)
                handled = TaskbarWindowManager.Instance.DispatchMessage(ref m, this.TabbedThumbnail.TaskbarWindow);

            // If it's a WM_Destroy message, then also forward it to the base class (our native window)
            if ((m.Msg == (int)TabbedThumbnailNativeMethods.WM_DESTROY) ||
               (m.Msg == (int)TabbedThumbnailNativeMethods.WM_NCDESTROY) ||
               ((m.Msg == (int)TabbedThumbnailNativeMethods.WM_SYSCOMMAND) && (((int)m.WParam) == TabbedThumbnailNativeMethods.SC_CLOSE)))
            {
                base.WndProc(ref m);
            }
            else if (!handled)
                base.WndProc(ref m);
        }

        #region IDisposable Members

        /// <summary>
        /// 
        /// </summary>
        ~TabbedThumbnailProxyWindow()
        {
            Dispose(false);
        }

        /// <summary>
        /// Release the native objects.
        /// </summary>
        void IDisposable.Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);

            base.Dispose();
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                // Dispose managed resources
                if (TabbedThumbnail != null)
                    TabbedThumbnail.Dispose();

                TabbedThumbnail = null;

                // 
                WindowsControl = null;
            }

            base.Dispose(disposing);
        }

        #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