protected override void WndProc(ref Message m)
{
switch (m.Msg)
{
case NativeMethods.WM_CREATE:
if (OsUtils.WinXpOrLater())
{
// Set the theme of the control to "explorer", to give the
// correct styling under Vista. This has no effect under XP.
Marshal.ThrowExceptionForHR(NativeMethods.SetWindowTheme(this.Handle, "explorer", null));
}
// Remove the focus rectangle from the control (and as a side effect, all other controls on the
// form) if the last input event came from the mouse, or add them if it came from the keyboard.
NativeMethods.SendMessage(this.Handle, NativeMethods.WM_CHANGEUISTATE, this.MakeLParam(NativeMethods.UIS_INITIALIZE, NativeMethods.UISF_HIDEFOCUS), IntPtr.Zero);
break;
case NativeMethods.LVM_SETEXTENDEDLISTVIEWSTYLE:
if (OsUtils.WinXpOrLater())
{
int styles = (int)m.LParam;
if ((styles & NativeMethods.LVS_EX_DOUBLEBUFFER) != NativeMethods.LVS_EX_DOUBLEBUFFER)
{
styles = styles | NativeMethods.LVS_EX_DOUBLEBUFFER;
m.LParam = (IntPtr)styles;
}
}
break;
case NativeMethods.WM_SETFOCUS:
// Remove the focus rectangle from the control (and as a side effect, all other controls on the
// form) if the last input event came from the mouse, or add them if it came from the keyboard.
NativeMethods.SendMessage(this.Handle, NativeMethods.WM_CHANGEUISTATE, this.MakeLParam(NativeMethods.UIS_INITIALIZE, NativeMethods.UISF_HIDEFOCUS), IntPtr.Zero);
break;
case NativeMethods.WM_NOTIFY:
// Test to see if the notification was for a right-click in the header
if (((NativeMethods.NMHDR)m.GetLParam(typeof(NativeMethods.NMHDR))).code == NativeMethods.NM_RCLICK)
{
// Fire an event to indicate the click has occurred. Set the column number
// to -1 for all clicks, as this information isn't currently required.
if (this.ColumnRightClick != null)
{
this.ColumnRightClick(this, new ColumnClickEventArgs(-1));
}
}
break;
case NativeMethods.WM_PAINT:
if (this.View != View.Details)
{
break;
}
// Calculate the position of all embedded controls
foreach (KeyValuePair <ListViewItem, EmbeddedProgress> embedded in this.embeddedInfo)
{
Rectangle rect = this.GetSubItemBounds(embedded.Key, embedded.Value.Column);
if (((this.HeaderStyle != ColumnHeaderStyle.None) && (rect.Top < this.Font.Height)) || (rect.Top + rect.Height) <= 0 || (rect.Top > this.ClientRectangle.Height))
{
// Control overlaps ColumnHeader, is off the top, or is off the bottom of the listview
embedded.Value.Progress.Visible = false;
continue;
}
else
{
embedded.Value.Progress.Visible = true;
}
// Set embedded control's bounds
embedded.Value.Progress.Bounds = rect;
}
break;
}
base.WndProc(ref m);
}