I'm running windows vista and want to get the appearance to look like regular vista programs. Are there any really good tutorials/articles on how to build Vista Style apps? I would also like to learn how to use the native code and convert it to C# like in this example.
If you're using WinForms it's relatively easy to accomplish it because WinForms is based on the native Win32 controls. Many controls have ways to enhance their rendering by setting additional flags (by sending messages to the native control) or using SetWindowTheme. This can be achieved through Interop.
As an example, take a simple ListView. If you want an explorer-style listview you use SetWindowTheme on the exposed handle of the ListView. We use interop to get access to the native SetWindowTheme() function, hook the window procedure of the ListView and apply the theme when the control is created:
static class NativeMethods
{
public const int WM_CREATE = 0x1;
[DllImport("uxtheme.dll", CharSet = CharSet.Unicode)]
public extern static int SetWindowTheme(
IntPtr hWnd, string pszSubAppName, string pszSubIdList);
}
class ListView : System.Windows.Forms.ListView
{
protected override void WndProc(ref Message m)
{
if (m.Msg == NativeMethods.WM_CREATE) {
NativeMethods.SetWindowTheme(this.Handle, "Explorer", null);
}
base.WndProc(ref m);
}
}
The difference between a default ListView and our enhanced version: ListView difference http://img100.imageshack.us/img100/1027/62586064nt6.png
Unfortunately there isn't one simple way for every control. Some controls don't even have any WinForms wrapper. Recently I stumbled upon a nice compilation in this CodeProject article which is worth a look. There may also be managed libraries out there that package this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With