Vista ProgressBar

Fri, June 8, 2007, 05:46 AM under Windows | Vista
While prepping for an event in Amsterdam next week, I am revisiting all my content from last year to do with Vista for managed developers. A very small part of the presentation is showing the WinForms controls and what additional things you can do with them in Vista such as the TextBox cue banner, commandlink button, treeviewvista, adding shield to clickable controls etc.

It occurred to me that I never looked at the ProgressBar control. In Vista, in addition to NORMAL (green), the control can be in a state of PAUSE (yellow) and ERROR (red). However, the managed ProgressBar control does not expose a managed way of controlling that. Once again, PInvoke to the rescue:
// Assuming a Form1 with 3 ProgressBar controls
private void Form1_Load(object sender, EventArgs e)
{
SendMessage(progressBar2.Handle,
0x400 + 16, //WM_USER + PBM_SETSTATE
0x0003, //PBST_PAUSED
0);

SendMessage(progressBar3.Handle,
0x400 + 16, //WM_USER + PBM_SETSTATE
0x0002, //PBST_ERROR
0);
}

[DllImport("user32.dll", CharSet = CharSet.Unicode)]
static extern uint SendMessage(IntPtr hWnd,
uint Msg,
uint wParam,
uint lParam);


For a more complete reusable wrapper of the ProgressBar (inc. some other features that I have not covered) check out the code from the VistaControls project on codeplex.
Comments are closed.