Using CreateParams and SetWindowTheme on a ListView at the same time

2.6k views Asked by At

I'm using the SetWindowTheme function (uxtheme.dll) to make my ListView look like Windows 7 native. I had to use the CreateParams stuff to prevent that ListView flickering when I sort it. It worked, but when I use that CreateParams code, the SetTheme doesn't work anymore. Is there a way to use the Windows 7 native theme and the CreateParams at the same time ?

protected override CreateParams CreateParams
{
    get
    {
        CreateParams cp = base.CreateParams;
        cp.ExStyle |= 0x02000000;  // Turn on WS_EX_COMPOSITED
        return cp;
    }
}


[DllImport("uxtheme.dll", ExactSpelling = true, CharSet = CharSet.Unicode)]
    private static extern int SetWindowTheme(IntPtr hwnd, string pszSubAppName, string pszSubIdList);

public MainWindow()
{
    InitializeComponent();
    SetWindowTheme(listView1.Handle, "Explorer", null);
}

Thanks

EDIT : I solved the problem by adding a SetWindowTheme call in the OnHandleCreated void of my custom ListView. Thanks to Hans Passant.

0

There are 0 answers