public static void SetHasChildren(TreeNode node, bool hasChildren) { TVITEM item = new TVITEM(); item.mask = TreeViewItemFlags.CHILDREN; item.hItem = node.Handle; item.cChildren = hasChildren ? 1 : 0; SendMessage(node.TreeView.Handle, TVM_SETITEMA, 0, ref item); }
/// <summary> /// Hides the checkbox for the specified node on a TreeView control. /// </summary> public static void HideCheckBox(this TreeNode node) { TVITEM tvi = new TVITEM(); tvi.hItem = node.Handle; tvi.mask = TVIF_STATE; tvi.stateMask = TVIS_STATEIMAGEMASK; tvi.state = 0; SendMessage(node.TreeView.Handle, TVM_SETITEM, IntPtr.Zero, ref tvi); }
private void HideCheckBox(TreeNode node) { TVITEM tvi = new TVITEM(); tvi.hItem = node.Handle; tvi.mask = TVIF_STATE; tvi.stateMask = TVIS_STATEIMAGEMASK; tvi.state = 0; IntPtr lparam = Marshal.AllocHGlobal(Marshal.SizeOf(tvi)); Marshal.StructureToPtr(tvi, lparam, false); SendMessage(this.file_list.Handle, TVM_SETITEM, IntPtr.Zero, lparam); }
string GetItemText(IntPtr hTreeItem) { string text; TVITEM tvi = new TVITEM(); tvi.hItem = hTreeItem; tvi.mask = (int)TreeViewItemFlags.TVIF_TEXT; tvi.cchTextMax = 80; tvi.pszText = Marshal.AllocHGlobal(80); WindowsAPI.SendMessage(Handle, (int)TreeViewMessages.TVM_GETITEMW, 0, ref tvi); text = Marshal.PtrToStringAuto(tvi.pszText); return(text); }
public static IntPtr TreeView_SetItemState(HandleRef hwndTV, IntPtr hti, uint data, uint _mask) { TVITEM _ms_TVi = new TVITEM(); _ms_TVi.mask = (uint)TVIF.TVIF_STATE; _ms_TVi.hItem = (hti); _ms_TVi.stateMask = (_mask); _ms_TVi.state = (data); IntPtr p = Marshal.AllocCoTaskMem(Marshal.SizeOf(_ms_TVi)); Marshal.StructureToPtr(_ms_TVi, p, false); IntPtr r = SendMessage(hwndTV, (int)TVM.TVM_SETITEMW, IntPtr.Zero, p); Marshal.FreeCoTaskMem(p); return r; }
public static uint GetTreeViewOverlay(TreeNode node) { var tvi = new TVITEM { mask = Win32.TVIF_STATE, hItem = node.Handle, stateMask = Win32.TVIS_OVERLAYMASK, state = 0 }; var ret = Win32.SendMessage(node.TreeView.Handle, Win32.TVM_GETITEMW, 0, ref tvi); return(tvi.state >> 8); }
public static bool GetTreeViewText(IntPtr AHandle, List <string> AOutput) { if (AOutput == null) { return(false); } uint vProcessId; GetWindowThreadProcessId(AHandle, out vProcessId); IntPtr vProcess = OpenProcess(PROCESS_VM_OPERATION | PROCESS_VM_READ | PROCESS_VM_WRITE, false, vProcessId); IntPtr vPointer = VirtualAllocEx(vProcess, IntPtr.Zero, 4096, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE); try { uint vItemCount = TreeView_GetCount(AHandle); IntPtr vTreeItem = TreeView_GetRoot(AHandle); Console.WriteLine(vItemCount); for (int i = 0; i < vItemCount; i++) { byte[] vBuffer = new byte[256]; TVITEM[] vItem = new TVITEM[1]; vItem[0] = new TVITEM(); vItem[0].mask = TVIF_TEXT; vItem[0].hItem = vTreeItem; vItem[0].pszText = (IntPtr)((int)vPointer + Marshal.SizeOf(typeof(TVITEM))); vItem[0].cchTextMax = vBuffer.Length; uint vNumberOfBytesRead = 0; WriteProcessMemory(vProcess, vPointer, Marshal.UnsafeAddrOfPinnedArrayElement(vItem, 0), Marshal.SizeOf(typeof(TVITEM)), ref vNumberOfBytesRead); SendMessage(AHandle, TVM_GETITEMA, 0, (int)vPointer); ReadProcessMemory(vProcess, (IntPtr)((int)vPointer + Marshal.SizeOf(typeof(TVITEM))), Marshal.UnsafeAddrOfPinnedArrayElement(vBuffer, 0), vBuffer.Length, ref vNumberOfBytesRead); Console.WriteLine(Marshal.PtrToStringAnsi( Marshal.UnsafeAddrOfPinnedArrayElement(vBuffer, 0))); vTreeItem = TreeNodeGetNext(AHandle, vTreeItem); } } finally { VirtualFreeEx(vProcess, vPointer, 0, MEM_RELEASE); CloseHandle(vProcess); } return(true); }
private static void UncheckNode(IntPtr handle, int hItem) { if (hItem > 0) { TVITEM tvi = new TVITEM(); tvi.mask = (uint)CommCtrl.TVIF_HANDLE | (uint)CommCtrl.TVIF_STATE; tvi.hItem = new IntPtr(hItem); tvi.stateMask = (uint)CommCtrl.TVIS_STATEIMAGEMASK; tvi.state = 0; User32.SendMessage(handle, CommCtrl.TVM_SETITEM, IntPtr.Zero, ref tvi); } }
public static void SetTreeViewOverlay(TreeNode node, uint overlayIndex) { // TreeView_SetItemState(node.TreeView.Handle, node.Handle, // overlayIndex << 8, TVIS_OVERLAYMASK); 相当の処理 var tvi = new TVITEM { mask = Win32.TVIF_STATE, hItem = node.Handle, stateMask = Win32.TVIS_OVERLAYMASK, state = (overlayIndex << 8) }; Win32.SendMessage(node.TreeView.Handle, Win32.TVM_SETITEMW, 0, ref tvi); }
private void HideCheckBox(TreeView tvw, TreeNode node) { TVITEM tvi = new TVITEM(); tvi.hItem = node.Handle; tvi.mask = TVIF_STATE; tvi.stateMask = TVIS_STATEIMAGEMASK; tvi.state = 0; SendMessage(tvw.Handle, TVM_SETITEM, IntPtr.Zero, ref tvi); }
public void SetNodeCheckState(TreeNode node, NodeCheckState checkState) { if (node.TreeView != this) { return; } TVITEM item = new TVITEM(); item.mask = TreeViewItemFlags.STATE | TreeViewItemFlags.HANDLE; item.stateMask = 0xF000; item.state = (int)checkState << 12; item.hItem = node.Handle; Win32Declarations.SendMessage(Handle, TreeViewMessage.TVM_SETITEMA, 0, ref item); }
protected void SetNodeSelectedState(TreeNode node, bool selected) { if (node.TreeView != this) { return; } TVITEM item = new TVITEM(); item.mask = TreeViewItemFlags.STATE | TreeViewItemFlags.HANDLE; item.stateMask = (int)TreeViewItemState.SELECTED; item.state = selected ? item.stateMask : 0; item.hItem = node.Handle; Win32Declarations.SendMessage(Handle, TreeViewMessage.TVM_SETITEMA, 0, ref item); }
public static IntPtr TreeView_SetItemState(HandleRef hwndTV, IntPtr hti, uint data, uint _mask) { TVITEM _ms_TVi = new TVITEM(); _ms_TVi.mask = (uint)TVIF.TVIF_STATE; _ms_TVi.hItem = (hti); _ms_TVi.stateMask = (_mask); _ms_TVi.state = (data); IntPtr p = Marshal.AllocCoTaskMem(Marshal.SizeOf(_ms_TVi)); Marshal.StructureToPtr(_ms_TVi, p, false); IntPtr r = SendMessage(hwndTV, (int)TVM.TVM_SETITEMW, IntPtr.Zero, p); Marshal.FreeCoTaskMem(p); return(r); }
public void SetTreeNodeState(TriStateTreeNode node, CheckBoxState state) { if (node == null) { return; } TVITEM tvItem = new TVITEM(); tvItem.mask = TVIF_HANDLE | TVIF_STATE; tvItem.hItem = node.Handle; tvItem.stateMask = TVIS_STATEIMAGEMASK; //State image index in bits 12..15 tvItem.state = ((int)state) << 12; SendMessage(this.Handle, TVM_SETITEM, 0, ref tvItem); }
// Hide TreeView CheckBox Code // -------------------------------------------------------------------------- #region Hide TreeView CheckBox Code static public void ShowCheckBox(TreeNode treeNode, bool show = true) { if (treeNode.TreeView == null) { return; } else { TVITEM tvi = new TVITEM(); tvi.hItem = treeNode.Handle; tvi.mask = TVIF_STATE; tvi.stateMask = TVIS_STATEIMAGEMASK; tvi.state = 0; IntPtr lparam = Marshal.AllocHGlobal(Marshal.SizeOf(tvi)); Marshal.StructureToPtr(tvi, lparam, false); SendMessage(treeNode.TreeView.Handle, TVM_SETITEM, IntPtr.Zero, lparam); } }
public string GetItemText(IntPtr handle) { TVITEM tvi = new TVITEM(); const int maxSize = 260; IntPtr pszText = LocalAlloc(0x40, maxSize); tvi.mask = TVIF_TEXT; tvi.hItem = handle; tvi.cchTextMax = 260; tvi.pszText = pszText; SendMessageTVI(Handle, TVM_GETITEM, IntPtr.Zero, ref tvi); string nodeText = Marshal.PtrToStringAnsi(tvi.pszText, maxSize); LocalFree(pszText); return(nodeText?.TrimEnd('\0')); }
private void HideCheckBox(TreeNode node) { TVITEM tvi = new TVITEM { hItem = node.Handle, mask = TVIF_STATE, stateMask = TVIS_STATEIMAGEMASK, state = 0, lpszText = null, cchTextMax = 0, iImage = 0, iSelectedImage = 0, cChildren = 0, lParam = IntPtr.Zero }; IntPtr lparam = Marshal.AllocHGlobal(Marshal.SizeOf(tvi)); Marshal.StructureToPtr(tvi, lparam, false); SendMessage(node.TreeView.Handle, TVM_SETITEM, IntPtr.Zero, lparam); }
private void RemoveCheckboxOnNode(TreeNode node) { TVITEM tvItem = new TVITEM(); tvItem.hItem = node.Handle; tvItem.mask = TVIF_STATE; tvItem.stateMask = TVIS_STATEIMAGEMASK; tvItem.state = 0; IntPtr lparam = Marshal.AllocHGlobal(Marshal.SizeOf(tvItem)); try { Marshal.StructureToPtr(tvItem, lparam, false); SendMessage(_groupsTreeView.Handle, TVM_SETITEM, IntPtr.Zero, lparam); } finally { Marshal.FreeHGlobal(lparam); } }
/// <summary> /// Associates an overlay image with a tree node. The overlay image is taken from the normal /// image list of the tree view the node is contained in. Also the overlay image must have been /// made available by <see cref="SetOverlayImage(ImageList,int,int)"/>. /// </summary> /// <param name="node">node to associate the overlay with</param> /// <param name="overlayIndex">index between 1 and 5 indicating the overlay image to use or 0 to indicate no image</param> public static void SetOverlayIndex(TreeNode node, int overlayIndex) { if (overlayIndex < 0 || overlayIndex > 5) throw new ArgumentOutOfRangeException("overlayIndex", overlayIndex, "overlay image must be between 0 and 5"); TVITEM tvi = new TVITEM(); // Define the item we want to set the State in. tvi.hItem = node.Handle; tvi.mask = TVIF_HANDLE | TVIF_STATE; // Left shift 8 to put info in bits 8 to 11 tvi.state = (uint)overlayIndex << 8; // activate the overlay information tvi.stateMask = TVIS_OVERLAYMASK; // Send the TVM_SETITEM message. SendMessage(node.TreeView.Handle, TVM_SETITEM, IntPtr.Zero, ref tvi); }
public bool Find(String name, out IntPtr foundItem, out IntPtr previousSelected) { IntPtr item = (IntPtr)SendMessage(r_hwnd, TVM_GETNEXTITEM, TVGN_ROOT, 0); foundItem = IntPtr.Zero; previousSelected = IntPtr.Zero; while (item != IntPtr.Zero) { TVITEM tvItem = new TVITEM(); IntPtr pszText = LocalAlloc(0x40, MY_MAXLVITEMTEXT); tvItem.hItem = item; tvItem.cchTextMax = MY_MAXLVITEMTEXT; tvItem.pszText = (int)pszText; tvItem.stateMask = TVIS_SELECTED; tvItem.mask = TVIF_TEXT | TVIF_STATE; int bGetItemPtr = SendMessageTVI(r_hwnd, TVM_GETITEM, 0, ref tvItem); String buffer = Marshal.PtrToStringUni((IntPtr)tvItem.pszText, MY_MAXLVITEMTEXT); LocalFree(pszText); int len = buffer.IndexOf('\0'); if (len > 0) { buffer = buffer.Substring(0, len); } buffer = buffer.Trim(); if (buffer == name) { foundItem = item; } else if ((tvItem.state & TVIS_SELECTED) == TVIS_SELECTED) { previousSelected = item; } item = (IntPtr)SendMessage(r_hwnd, TVM_GETNEXTITEM, TVGN_NEXT, (uint)item.ToInt32()); } return(foundItem != IntPtr.Zero); }
/// <summary> /// Associates an overlay image with a tree node. The overlay image is taken from the normal /// image list of the tree view the node is contained in. Also the overlay image must have been /// made available by <see cref="SetOverlayImage(ImageList,int,int)"/>. /// </summary> /// <param name="node">node to associate the overlay with</param> /// <param name="overlayIndex">index between 1 and 5 indicating the overlay image to use or 0 to indicate no image</param> public static void SetOverlayIndex(TreeNode node, int overlayIndex) { if (overlayIndex < 0 || overlayIndex > 5) { throw new ArgumentOutOfRangeException("overlayIndex", overlayIndex, "overlay image must be between 0 and 5"); } TVITEM tvi = new TVITEM(); // Define the item we want to set the State in. tvi.hItem = node.Handle; tvi.mask = TVIF_HANDLE | TVIF_STATE; // Left shift 8 to put info in bits 8 to 11 tvi.state = (uint)overlayIndex << 8; // activate the overlay information tvi.stateMask = TVIS_OVERLAYMASK; // Send the TVM_SETITEM message. SendMessage(node.TreeView.Handle, TVM_SETITEM, IntPtr.Zero, ref tvi); }
public bool Find(String name, out IntPtr foundItem, out IntPtr previousSelected) { IntPtr item = (IntPtr)SendMessage(r_hwnd, TVM_GETNEXTITEM, TVGN_ROOT, 0); foundItem = IntPtr.Zero; previousSelected = IntPtr.Zero; while (item != IntPtr.Zero) { TVITEM tvItem = new TVITEM(); IntPtr pszText = LocalAlloc(0x40, MY_MAXLVITEMTEXT); tvItem.hItem = item; tvItem.cchTextMax = MY_MAXLVITEMTEXT; tvItem.pszText = (int)pszText; tvItem.stateMask = TVIS_SELECTED; tvItem.mask = TVIF_TEXT | TVIF_STATE; int bGetItemPtr = SendMessageTVI(r_hwnd, TVM_GETITEM, 0, ref tvItem); String buffer = Marshal.PtrToStringUni((IntPtr)tvItem.pszText, MY_MAXLVITEMTEXT); LocalFree(pszText); int len = buffer.IndexOf('\0'); if (len > 0) { buffer = buffer.Substring(0, len); } buffer = buffer.Trim(); if (buffer == name) { foundItem = item; } else if ((tvItem.state & TVIS_SELECTED) == TVIS_SELECTED) { previousSelected = item; } item = (IntPtr)SendMessage(r_hwnd, TVM_GETNEXTITEM, TVGN_NEXT, (uint)item.ToInt32()); } return foundItem != IntPtr.Zero; }
/// <summary> /// Sets a value indicating if the checkbox is visible on the tree node. /// </summary> /// <param name="node">The tree node.</param> /// <param name="value"><value>true</value> to make the checkbox visible on the tree node; otherwise <value>false</value>.</param> public static void SetIsCheckBoxVisible(this TreeNode node, bool value) { if (node == null) { throw new ArgumentNullException("node"); } if (node.TreeView == null) { throw new InvalidOperationException("The node does not belong to a tree."); } var tvi = new TVITEM { hItem = node.Handle, mask = TVIF_STATE, stateMask = TVIS_STATEIMAGEMASK, state = (value ? node.Checked ? 2 : 1 : 0) << 12 }; var result = SendMessage(node.TreeView.Handle, TVM_SETITEM, IntPtr.Zero, ref tvi); if (result == IntPtr.Zero) { throw new ApplicationException("Error setting TreeNode state."); } }
public static extern bool SendMessage(IntPtr hWnd, int msg, int wParam, ref TVITEM tvItem);
private static extern int SendMessageTVI(IntPtr hWnd, int wMsg, int wParam, ref TVITEM tvi);
private void HideCheckBox(TreeNode node) { TVITEM tvi = new TVITEM(); tvi.hItem = node.Handle; tvi.mask = TVIF_STATE; tvi.stateMask = TVIS_STATEIMAGEMASK; tvi.state = 0; IntPtr lparam = Marshal.AllocHGlobal(Marshal.SizeOf(tvi)); Marshal.StructureToPtr(tvi, lparam, false); SendMessage(this.tvTags.Handle, TVM_SETITEM, IntPtr.Zero, lparam); }
public static extern int SendMessage(int hWnd, Int32 msg, Int32 wParam, ref TVITEM tvItem);
private static extern IntPtr SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, ref TVITEM lParam);
public static extern IntPtr SendMessage(IntPtr hwnd, int msg, int wparam, ref TVITEM lparam);
public static extern bool WriteProcessMemory(int hProcess, int lpBaseAddress, ref TVITEM buffer, int dwSize, int lpNumberOfBytesWritten);
internal static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, ref TVITEM buffer, int dwSize, IntPtr lpNumberOfBytesWritten);
public static extern IntPtr SendMessage(IntPtr hWnd, Int32 msg, Int32 wParam, ref TVITEM tvItem);
public static extern IntPtr SendMessage(IntPtr hWnd, int msg, int wParam, ref TVITEM lParam);
/// <summary> /// Sets a value indicating if the checkbox is visible on the tree node. /// </summary> /// <param name="node">The tree node.</param> /// <param name="isVisible"><value>true</value> to make the checkbox visible on the tree node; otherwise <value>false</value>.</param> public static void SetIsCheckBoxVisible(this TreeNode node, bool isVisible, bool applyToSubtree = false) { if (node.TreeView == null) throw new InvalidOperationException("The node does not belong to a tree."); var tvi = new TVITEM { hItem = node.Handle, mask = TVIF_STATE, stateMask = TVIS_STATEIMAGEMASK, state = (isVisible ? node.Checked ? 2 : 1 : 0) << 12 }; var result = SendMessage(node.TreeView.Handle, TVM_SETITEM, IntPtr.Zero, ref tvi); if (result == IntPtr.Zero) throw new ApplicationException("Error setting TreeNode state."); if (applyToSubtree) { foreach (var childNode in node.GetTreeNodes()) { childNode.SetIsCheckBoxVisible(isVisible, applyToSubtree); } } }
public static extern int SendMessage( IntPtr hwnd, uint msg, uint wParam, ref TVITEM lParam);
public static extern Int32 SendMessage(int hWnd, int Msg, int wParam, TVITEM tvi);
static extern IntPtr SendMessageTVI(IntPtr hWnd, UInt32 Msg, IntPtr wParam, ref TVITEM tvi);
public CheckBoxState GetTreeNodeState(TriStateTreeNode node) { TVITEM tvItem = new TVITEM(); tvItem.mask = TVIF_HANDLE | TVIF_STATE; tvItem.hItem = node.Handle; tvItem.stateMask = TVIS_STATEIMAGEMASK; tvItem.state = 0; IntPtr ptr = SendMessage(this.Handle, TVM_GETITEM, 0, ref tvItem); if (ptr != null) { //State image index in bits 12..15 int iState = tvItem.state >> 12; if (iState == (int)CheckBoxState.None) return CheckBoxState.None; if (iState == (int)CheckBoxState.Unchecked) return CheckBoxState.Unchecked; if (iState == (int)CheckBoxState.Checked) return CheckBoxState.Checked; if (iState == (int)CheckBoxState.Indeterminate) return CheckBoxState.Indeterminate; } return CheckBoxState.None; }
public static extern bool WriteProcessMemory( int hProcess, int lpBaseAddress, ref TVITEM buffer, int dwSize, int lpNumberOfBytesWritten );
private void TreeViewControl_DrawNode(object sender, DrawTreeNodeEventArgs e) { // Disable the checkbox for top level nodes such as Views and Sprocs if they have no children. if (e.Node.Level == 0 && e.Node.Nodes.Count == 0) { var tvi = new TVITEM { hItem = e.Node.Handle, mask = TVIF_STATE, stateMask = TVIS_STATEIMAGEMASK, state = 1 << 12 }; var lparam = IntPtr.Zero; try { lparam = Marshal.AllocHGlobal(Marshal.SizeOf(tvi)); Marshal.StructureToPtr(tvi, lparam, false); NativeMethods.SendMessage(treeView.Handle, TVM_SETITEM, IntPtr.Zero, lparam); } finally { if (lparam != IntPtr.Zero) { Marshal.FreeHGlobal(lparam); } } } e.DrawDefault = true; }
public static extern IntPtr SendMessage(IntPtr hWnd, UInt32 Msg, IntPtr wParam, ref TVITEM lParam);
public void SetTreeNodeState(TriStateTreeNode node, CheckBoxState state) { if (node == null) return; TVITEM tvItem = new TVITEM(); tvItem.mask = TVIF_HANDLE | TVIF_STATE; tvItem.hItem = node.Handle; tvItem.stateMask = TVIS_STATEIMAGEMASK; //State image index in bits 12..15 tvItem.state = ((int)state) << 12; SendMessage(this.Handle, TVM_SETITEM, 0, ref tvItem); }
private static extern UInt32 SendMessage(IntPtr hWnd, UInt32 msg, UInt32 wParam, ref TVITEM lParam);
internal static extern IntPtr SendMessage(IntPtr hWnd, UInt32 msg, IntPtr wParam, ref TVITEM lParam);
private static extern IntPtr SendMessage(IntPtr hWnd, [MarshalAs(UnmanagedType.U4)] int msg, IntPtr wParam, ref TVITEM item);
/// <summary> /// Gets a value indicating if the checkbox is visible on the tree node. /// </summary> /// <param name="node">The tree node.</param> /// <returns><value>true</value> if the checkbox is visible on the tree node; otherwise <value>false</value>.</returns> public static bool IsCheckBoxVisible(this TreeNode node) { if (node == null) throw new ArgumentNullException("node"); if (node.TreeView == null) throw new InvalidOperationException("The node does not belong to a tree."); var tvi = new TVITEM { hItem = node.Handle, mask = TVIF_STATE }; var result = SendMessage(node.TreeView.Handle, TVM_GETITEM, node.Handle, ref tvi); if (result == IntPtr.Zero) throw new ApplicationException("Error getting TreeNode state."); var imageIndex = (tvi.state & TVIS_STATEIMAGEMASK) >> 12; return (imageIndex != 0); }
/// <summary> /// Hides the checkbox for the specified node on a TreeView control. /// </summary> private void HideCheckBox(TreeView tvw, TreeNode node) { TVITEM tvi = new TVITEM(); if (node.Handle != null) { try { tvi.hItem = node.Handle; tvi.mask = TVIF_STATE; tvi.stateMask = TVIS_STATEIMAGEMASK; tvi.state = 0; SendMessage(tvw.Handle, TVM_SETITEM, IntPtr.Zero, ref tvi); } catch (Exception ex) { Hanbo.Log.LogManager.Error(ex); } } }