bright, fresh software
Downloads  |  Buy

Wyatt Says...

Posts Tagged ‘open source’

This will be another easy tip because all the work is already done and wrapped up in a nice little control. It’s open source and handles all of the details, get it here.

Progress bars in Windows 7 are nearly identical to what they were in Windows Vista. They’re green, animated and have 3 states: Normal, Error, and Paused:

Using Windows API

To get both the 3-state progress bar (regular, error, and paused) along with the taskbar progress bar we need to use some Windows API. The easier of the two to implement is changing the state of the progress bar. This works on Windows Vista and Windows 7:

[DllImport("user32.dll", CharSet = CharSet.Auto)]
internal static extern int SendMessage(IntPtr hWnd, int wMsg, int wParam, int lParam);

SetPaused()
{
    // 0x410 = PBM_SETSTATE
    // 0x0003 = PBST_PAUSE
    SendMessage(progressBar.Handle, 0x410, 0x0003, 0);
}

SetError()
{
    // 0x0002 = PBST_ERROR
    SendMessage(progressBar.Handle, 0x410, 0x0002, 0);
}

SetNormal()
{
    // 0x0001 = PBST_NORMAL
    SendMessage(progressBar.Handle, 0x410, 0x0001, 0);
}

Then there’s the matter of the taskbar progress bar in Windows 7. You can download the Windows7ProgressBar source code (zip file) to see how I did it, but the gist of it is you need to implement the ITakbarList3 Interface, and then use the SetProgressState to set the state (Normal, Error, Paused, or Marquee) and SetProgressValue to set the value.

7 Days of Windows 7

Join me Monday when I talk about Drag & Drop icons. See the full list of articles in the series.

Those of you who follow this blog regularly already know the tip I’m sharing today. It’s about the control I created a couple of years ago: VistaMenu.

Normally I would just show a menu from Windows 7 and say “this is how you do it”. Take the menu above, for example. It’s the context menu when you right click the desktop in Windows 7. It’s subtle and usable. It’s less about being visually appealing than it is about being usable.

I find Windows Vista and Windows 7 menus to be aesthetically pleasing. However, not everyone would agree.

Aesthetics – ask 1000 people, get 1000 opinions

How do you judge art? It’s damn near impossible to get 100% consensus. Luckily programs aren’t art – they have utility first and style second.

Or, put more simply, if the style detracts from usability it is bad style.

Here are a couple of examples of bad menus. The following menus are tacky for the simple reason that the styling adds no extras usability. The excessive gradients and bad backgrounds distracts from the purpose of the menus:

Difference between MenuStrip and MainMenu

If you’ve been programming with Windows Forms for any length of time, it’s very likely you already use MenuStrips and ContextMenuStrips. They are entirely custom-draw menus created by Microsoft and included in .NET Framework 2.0+.

However, the theme of the MenuStrip and ContextMenuStrip controls don’t automatically adjust to match the Windows 7 theme. But, as you can see below, the MainMenu and ContextMenu controls do match the Windows 7 theme.

You can add MainMenu & ContextMenu to Visual Studio by right clicking the toolbox, clicking “Choose Items…” and checking the “MainMenu” and “ContextMenu” check boxes.

Why you should always use MainMenu

If all the discussion of aesthetics was lost on you, then you should always use MainMenu for two simple reasons:

  1. Your program will look like it fits in with all the other programs on your users’ computers
  2. Microsoft does the hard work for you. That is, with each new version of Windows Microsoft subtly tweaks the menu to be more usable.

The MenuStrip and ContextMenuStrip controls are written entirely in C# and will forever look as tacky as they do now. The MainMenu and ContextMenu, however, are simple wrappers around the Windows API. This means that whenever Microsoft updates the menu API in Windows you will get all the usability improvements without lifting a finger.

Look at the screenshot below and you can see how Microsoft even changed the menu API between Windows Vista and Windows 7. The borders are sharper, the colors are tweaked, and the gradient is toned down.

Adding icons to MainMenu and ContextMenus

Microsoft was good enough to add simple API for adding icons to menus. I wrote a .NET wrapper for this API a couple of years ago, VistaMenu. Enough chit-chat, here’s how you use VistaMenu. It’s open source and works with Windows 98 – Windows 7.

7 Days of Windows 7

Join me tomorrow when I talk about Windows 7 progress bars. See the full list of articles in the series.

For the next 7 Days I’ll be giving 7 C# & .NET tips to make your Windows application look like it was built for Vista and Windows 7. All of these tips are used in our products (wyBuild, wyUpdate, and LimeLM) and they range from the simple one-liner, free open source controls, and to the advanced tip.

And since wyBuild, wyUpdate, and LimeLM are all compatible with Windows 2000 through Windows 7 all of these tips will be backward compatible.

7 days of Windows 7

Day 1: Windows Vista & 7 Font, Segoe UI, in C# and VB.NET
Day 2: Making the menus in your .NET app look professional
Day 3: Windows 7 Progress Bar in .NET
Day 4: Drag & drop icons in .NET – Windows 2000, XP, Vista, and 7
Day 5: Shield icons, UAC, and process elevation in .NET on Windows 2000, XP, Vista, and 7
Day 6: Windows Vista and Windows 7 .NET Controls – Every possible one you could ever want
Day 7: Finishing touches: Make your .NET app shine with professionalism