protected override void WndProc(ref Message message) { bool oldLabelEdit = LabelEdit; switch (message.Msg) { case (int)Msg.WM_LBUTTONDOWN: POINT p = new POINT((int)message.LParam); TVHITTESTINFO ht = HitTest(p); if (ht.hItem != IntPtr.Zero && !m_SelectedItems.Contains((int)ht.hItem)) { LabelEdit = false; SelectTreeItem(ht.hItem); } break; // Reflected Messages come from the treeview control itself case (int)ReflectedMessages.OCM_NOTIFY: NMHDR nm2 = (NMHDR)message.GetLParam(typeof(NMHDR)); switch (nm2.code) { case (int)NotificationMessages.NM_CUSTOMDRAW: base.WndProc(ref message); NotifyTreeCustomDraw(ref message); return; case (int)TreeViewNotification.TVN_DeleteItem: NMTREEVIEW tv = (NMTREEVIEW)message.GetLParam(typeof(NMTREEVIEW)); if (m_SelectedItems.Contains((int)tv.itemOld.hItem)) { m_SelectedItems.Remove((int)tv.itemOld.hItem); m_selectionChanged = true; OnSelectionChanged(); } break; case (int)TreeViewNotification.TVN_SelectionChanged: NMTREEVIEW tv1 = (NMTREEVIEW)message.GetLParam(typeof(NMTREEVIEW)); int hItem = (int)tv1.itemNew.hItem; if ((WindowsAPI.GetKeyState((int)VirtualKeys.VK_SHIFT) | 1) != 1) { if (!m_SelectedItems.Contains(hItem)) { m_SelectedItems.Add(hItem); } else { m_SelectedItems.Remove(hItem); } } else if ((WindowsAPI.GetKeyState((int)VirtualKeys.VK_CONTROL) | 1) != 1) { if (!m_SelectedItems.Contains(hItem)) { m_SelectedItems.Add(hItem); } else { m_SelectedItems.Remove(hItem); } } else { bool bFullInvalidate = m_SelectedItems.Count > 1; m_SelectedItems.Clear(); m_SelectedItems.Add(hItem); if (bFullInvalidate) { Invalidate(); } } m_selectionChanged = true; OnSelectionChanged(); break; default: break; } break; default: break; } base.WndProc(ref message); LabelEdit = oldLabelEdit; }
internal static extern IntPtr SendMessage(IntPtr hWnd, int msg, IntPtr wParam, ref NMTREEVIEW lParam);