Click here to Skip to main content
15,895,827 members
Articles / Programming Languages / Visual Basic

Windows 7 new features: Step by step in VB.NET and C#

Rate me:
Please Sign up or sign in to vote.
4.85/5 (88 votes)
31 Aug 2010CPOL9 min read 179.9K   4.7K   211  
Explaining all the new must have features in Windows 7 to make your application look shiny and professional, like the new features of the task bar and more.
// 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
Software Developer IDS
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions