Click here to Skip to main content
15,896,606 members
Articles / Programming Languages / C#

Fully themed Windows Vista Controls

Rate me:
Please Sign up or sign in to vote.
4.91/5 (60 votes)
16 Jun 2007Ms-PL9 min read 323.5K   7.8K   226  
Render Windows Controls fully (with special fade effects) in Windows Vista
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Drawing;

namespace VistaControls
{
    public class ExplorerListView: ListView
    {
        public const int LVM_FIRST = 0x1000; //Value from http://www.winehq.org/pipermail/wine-devel/2002-October/009527.html
        public const int LVM_SETEXTENDEDLISTVIEWSTYLE = LVM_FIRST + 54;
        public const int LVS_EX_DOUBLEBUFFER = 0x00010000;
        [DllImport("user32.dll", CharSet = CharSet.Auto)]
        public static extern IntPtr SendMessage(IntPtr hWnd, int msg, int wParam, int lParam);
        //Imports the UXTheme DLL
        [DllImport("uxtheme", CharSet = CharSet.Unicode)]
        public extern static Int32 SetWindowTheme(IntPtr hWnd, String textSubAppName, String textSubIdList);

        public ExplorerListView()
        {
            //Unknown problem: Calling anything that affects the interface here has no effect
            //SetWindowTheme(this.Handle, "explorer", null); //Explorer style
            //SendMessage(this.Handle, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_DOUBLEBUFFER); //Blue selection
            this.Enter += new EventHandler(ExplorerListView_Load);
        }

        //1-time execution, to set the theme; Used to render the control at run-time without extra code
        private Boolean elv = false;
        public void ExplorerListView_Load(object sender, EventArgs e)
        {
            if (!elv)
            {
            SetWindowTheme(this.Handle, "explorer", null); //Explorer style
            SendMessage(this.Handle, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_DOUBLEBUFFER); //Blue selection
            elv = true;
            }
        }

    }
}

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 Microsoft Public License (Ms-PL)


Written By
Software Developer
Singapore Singapore
My other projects at Onfry

Comments and Discussions