private void UpdateNode(int mask) { if (this.handle != IntPtr.Zero) { System.Windows.Forms.TreeView treeView = this.TreeView; System.Windows.Forms.NativeMethods.TV_ITEM lParam = new System.Windows.Forms.NativeMethods.TV_ITEM { mask = 0x10 | mask, hItem = this.handle }; if ((mask & 1) != 0) { lParam.pszText = Marshal.StringToHGlobalAuto(this.text); } if ((mask & 2) != 0) { lParam.iImage = (this.ImageIndexer.ActualIndex == -1) ? treeView.ImageIndexer.ActualIndex : this.ImageIndexer.ActualIndex; } if ((mask & 0x20) != 0) { lParam.iSelectedImage = (this.SelectedImageIndexer.ActualIndex == -1) ? treeView.SelectedImageIndexer.ActualIndex : this.SelectedImageIndexer.ActualIndex; } if ((mask & 8) != 0) { lParam.stateMask = 0xf000; if (this.StateImageIndexer.ActualIndex != -1) { lParam.state = (this.StateImageIndexer.ActualIndex + 1) << 12; } } if ((mask & 4) != 0) { lParam.lParam = this.handle; } System.Windows.Forms.UnsafeNativeMethods.SendMessage(new HandleRef(treeView, treeView.Handle), System.Windows.Forms.NativeMethods.TVM_SETITEM, 0, ref lParam); if ((mask & 1) != 0) { Marshal.FreeHGlobal(lParam.pszText); if (treeView.Scrollable) { treeView.ForceScrollbarUpdate(false); } } } }
private void ResetExpandedState(System.Windows.Forms.TreeView tv) { System.Windows.Forms.NativeMethods.TV_ITEM lParam = new System.Windows.Forms.NativeMethods.TV_ITEM { mask = 0x18, hItem = this.handle, stateMask = 0x40, state = 0 }; System.Windows.Forms.UnsafeNativeMethods.SendMessage(new HandleRef(tv, tv.Handle), System.Windows.Forms.NativeMethods.TVM_SETITEM, 0, ref lParam); }
internal void UpdateImage() { System.Windows.Forms.NativeMethods.TV_ITEM lParam = new System.Windows.Forms.NativeMethods.TV_ITEM { mask = 0x12, hItem = this.Handle, iImage = Math.Max(0, (this.ImageIndexer.ActualIndex >= this.TreeView.ImageList.Images.Count) ? (this.TreeView.ImageList.Images.Count - 1) : this.ImageIndexer.ActualIndex) }; System.Windows.Forms.UnsafeNativeMethods.SendMessage(new HandleRef(this.TreeView, this.TreeView.Handle), System.Windows.Forms.NativeMethods.TVM_SETITEM, 0, ref lParam); }
protected override void WndProc(ref Message m) { switch (m.Msg) { case 0x4e: { System.Windows.Forms.NativeMethods.NMHDR lParam = (System.Windows.Forms.NativeMethods.NMHDR) m.GetLParam(typeof(System.Windows.Forms.NativeMethods.NMHDR)); switch (lParam.code) { case -521: if (!this.WmShowToolTip(ref m)) { base.WndProc(ref m); return; } m.Result = (IntPtr) 1; return; case -520: case -530: System.Windows.Forms.UnsafeNativeMethods.SendMessage(new HandleRef(lParam, lParam.hwndFrom), 0x418, 0, SystemInformation.MaxWindowTrackSize.Width); this.WmNeedText(ref m); m.Result = (IntPtr) 1; return; } base.WndProc(ref m); return; } case 0x7b: { if (this.treeViewState[0x2000]) { this.treeViewState[0x2000] = false; base.WndProc(ref m); return; } TreeNode selectedNode = this.SelectedNode; if ((selectedNode == null) || ((selectedNode.ContextMenu == null) && (selectedNode.ContextMenuStrip == null))) { base.WndProc(ref m); return; } Point pt = new Point(selectedNode.Bounds.X, selectedNode.Bounds.Y + (selectedNode.Bounds.Height / 2)); if (base.ClientRectangle.Contains(pt)) { if (selectedNode.ContextMenu != null) { selectedNode.ContextMenu.Show(this, pt); return; } if (selectedNode.ContextMenuStrip == null) { return; } bool isKeyboardActivated = ((int) ((long) m.LParam)) == -1; selectedNode.ContextMenuStrip.ShowInternal(this, pt, isKeyboardActivated); } return; } case 0x83: case 5: case 70: case 0x47: if (this.treeViewState[0x8000]) { this.DefWndProc(ref m); return; } base.WndProc(ref m); return; case 7: if (!this.treeViewState[0x4000]) { base.WndProc(ref m); return; } this.treeViewState[0x4000] = false; base.WmImeSetFocus(); this.DefWndProc(ref m); this.OnGotFocus(EventArgs.Empty); return; case 0x15: base.SendMessage(0x1107, this.Indent, 0); base.WndProc(ref m); return; case 0x201: { try { this.treeViewState[0x10000] = true; this.FocusInternal(); } finally { this.treeViewState[0x10000] = false; } this.treeViewState[0x1000] = false; System.Windows.Forms.NativeMethods.TV_HITTESTINFO tv_hittestinfo = new System.Windows.Forms.NativeMethods.TV_HITTESTINFO { pt_x = System.Windows.Forms.NativeMethods.Util.SignedLOWORD(m.LParam), pt_y = System.Windows.Forms.NativeMethods.Util.SignedHIWORD(m.LParam) }; this.hNodeMouseDown = System.Windows.Forms.UnsafeNativeMethods.SendMessage(new HandleRef(this, base.Handle), 0x1111, 0, tv_hittestinfo); if ((tv_hittestinfo.flags & 0x40) != 0) { this.OnMouseDown(new MouseEventArgs(MouseButtons.Left, 1, System.Windows.Forms.NativeMethods.Util.SignedLOWORD(m.LParam), System.Windows.Forms.NativeMethods.Util.SignedHIWORD(m.LParam), 0)); if (!base.ValidationCancelled && this.CheckBoxes) { TreeNode node = this.NodeFromHandle(this.hNodeMouseDown); if (!this.TreeViewBeforeCheck(node, TreeViewAction.ByMouse) && (node != null)) { node.CheckedInternal = !node.CheckedInternal; this.TreeViewAfterCheck(node, TreeViewAction.ByMouse); } } m.Result = IntPtr.Zero; } else { this.WmMouseDown(ref m, MouseButtons.Left, 1); } this.downButton = MouseButtons.Left; return; } case 0x202: case 0x205: { System.Windows.Forms.NativeMethods.TV_HITTESTINFO tv_hittestinfo2 = new System.Windows.Forms.NativeMethods.TV_HITTESTINFO { pt_x = System.Windows.Forms.NativeMethods.Util.SignedLOWORD(m.LParam), pt_y = System.Windows.Forms.NativeMethods.Util.SignedHIWORD(m.LParam) }; IntPtr handle = System.Windows.Forms.UnsafeNativeMethods.SendMessage(new HandleRef(this, base.Handle), 0x1111, 0, tv_hittestinfo2); if (handle != IntPtr.Zero) { if (!base.ValidationCancelled && (!this.treeViewState[0x800] & !this.treeViewState[0x1000])) { if (handle == this.hNodeMouseDown) { this.OnNodeMouseClick(new TreeNodeMouseClickEventArgs(this.NodeFromHandle(handle), this.downButton, 1, System.Windows.Forms.NativeMethods.Util.SignedLOWORD(m.LParam), System.Windows.Forms.NativeMethods.Util.SignedHIWORD(m.LParam))); } this.OnClick(new MouseEventArgs(this.downButton, 1, System.Windows.Forms.NativeMethods.Util.SignedLOWORD(m.LParam), System.Windows.Forms.NativeMethods.Util.SignedHIWORD(m.LParam), 0)); this.OnMouseClick(new MouseEventArgs(this.downButton, 1, System.Windows.Forms.NativeMethods.Util.SignedLOWORD(m.LParam), System.Windows.Forms.NativeMethods.Util.SignedHIWORD(m.LParam), 0)); } if (this.treeViewState[0x800]) { this.treeViewState[0x800] = false; if (!base.ValidationCancelled) { this.OnNodeMouseDoubleClick(new TreeNodeMouseClickEventArgs(this.NodeFromHandle(handle), this.downButton, 2, System.Windows.Forms.NativeMethods.Util.SignedLOWORD(m.LParam), System.Windows.Forms.NativeMethods.Util.SignedHIWORD(m.LParam))); this.OnDoubleClick(new MouseEventArgs(this.downButton, 2, System.Windows.Forms.NativeMethods.Util.SignedLOWORD(m.LParam), System.Windows.Forms.NativeMethods.Util.SignedHIWORD(m.LParam), 0)); this.OnMouseDoubleClick(new MouseEventArgs(this.downButton, 2, System.Windows.Forms.NativeMethods.Util.SignedLOWORD(m.LParam), System.Windows.Forms.NativeMethods.Util.SignedHIWORD(m.LParam), 0)); } } } if (!this.treeViewState[0x1000]) { this.OnMouseUp(new MouseEventArgs(this.downButton, 1, System.Windows.Forms.NativeMethods.Util.SignedLOWORD(m.LParam), System.Windows.Forms.NativeMethods.Util.SignedHIWORD(m.LParam), 0)); } this.treeViewState[0x800] = false; this.treeViewState[0x1000] = false; base.CaptureInternal = false; this.hNodeMouseDown = IntPtr.Zero; return; } case 0x203: this.WmMouseDown(ref m, MouseButtons.Left, 2); this.treeViewState[0x800] = true; this.treeViewState[0x1000] = false; base.CaptureInternal = true; return; case 0x204: { this.treeViewState[0x1000] = false; System.Windows.Forms.NativeMethods.TV_HITTESTINFO tv_hittestinfo3 = new System.Windows.Forms.NativeMethods.TV_HITTESTINFO { pt_x = System.Windows.Forms.NativeMethods.Util.SignedLOWORD(m.LParam), pt_y = System.Windows.Forms.NativeMethods.Util.SignedHIWORD(m.LParam) }; this.hNodeMouseDown = System.Windows.Forms.UnsafeNativeMethods.SendMessage(new HandleRef(this, base.Handle), 0x1111, 0, tv_hittestinfo3); this.WmMouseDown(ref m, MouseButtons.Right, 1); this.downButton = MouseButtons.Right; return; } case 0x206: this.WmMouseDown(ref m, MouseButtons.Right, 2); this.treeViewState[0x800] = true; this.treeViewState[0x1000] = false; base.CaptureInternal = true; return; case 0x207: this.treeViewState[0x1000] = false; this.WmMouseDown(ref m, MouseButtons.Middle, 1); this.downButton = MouseButtons.Middle; return; case 0x209: this.treeViewState[0x1000] = false; this.WmMouseDown(ref m, MouseButtons.Middle, 2); return; case 0x2a3: this.prevHoveredNode = null; base.WndProc(ref m); return; case 0x114: base.WndProc(ref m); if (this.DrawMode == TreeViewDrawMode.OwnerDrawAll) { base.Invalidate(); } return; case 0x113f: case 0x110d: base.WndProc(ref m); if (this.CheckBoxes) { System.Windows.Forms.NativeMethods.TV_ITEM tv_item = (System.Windows.Forms.NativeMethods.TV_ITEM) m.GetLParam(typeof(System.Windows.Forms.NativeMethods.TV_ITEM)); if (!(tv_item.hItem != IntPtr.Zero)) { return; } System.Windows.Forms.NativeMethods.TV_ITEM tv_item2 = new System.Windows.Forms.NativeMethods.TV_ITEM { mask = 0x18, hItem = tv_item.hItem, stateMask = 0xf000 }; System.Windows.Forms.UnsafeNativeMethods.SendMessage(new HandleRef(null, base.Handle), System.Windows.Forms.NativeMethods.TVM_GETITEM, 0, ref tv_item2); this.NodeFromHandle(tv_item.hItem).CheckedStateInternal = (tv_item2.state >> 12) > 1; } return; case 0x204e: this.WmNotify(ref m); return; case 0x317: this.WmPrint(ref m); return; } base.WndProc(ref m); }