How to obtain the window handle of a TreeNode with v1.1.4322

I

IndridCold

As far as i can tell, the TreeNode class in the CF does not inherit
from control, meaning it's not a window and won't have it's own window
handle...
 
P

Peter Foot [MVP]

The TreeNode handle isn't a window handle but an identifier for the node
within a specific treeview control. You can possibly read this via
reflection - the internal field m_htvi (IntPtr) within the TreeNode class.
However many of the handles within .NETCF are psuedohandles and aren't those
directly used by the native control, you'd need to do some testing.

Peter
 
S

SwissPinoy

It does appear as if m_htvi would be the correct value and I can get
the value of m_htvi using reflection, but it doesn't seem to work for
what I'm trying to do using the code below. Basically, I'm just trying
to hide a node checkbox.


[DllImport("coredll", CharSet=CharSet.Auto)]
public static extern IntPtr SendMessage(IntPtr hWnd, int msg,
IntPtr wParam, ref TVITEM lParam);

[DllImport("coredll.dll")]
private static extern IntPtr GetCapture();

public int TVIF_STATE = 8;
public int TVIS_STATEIMAGEMASK = 61440;
public int TV_FIRST = 4352;
public int TVM_SETITEM = 4415;

[StructLayout(LayoutKind.Sequential)] public struct TVITEM
{
public int mask;
public IntPtr hItem;
public int state;
public int stateMask;
public IntPtr pszText;
public int cchTextMax;
public int iImage;
public int iSelectedImage;
public int cChildren;
public IntPtr lParam;
}

public void HideCheckBox(System.Windows.Forms.TreeNode node)
{
//Gets the node handle
System.Reflection.FieldInfo nodeInfo =
node.GetType().GetField("m_htvi", BindingFlags.NonPublic |
BindingFlags.Instance | BindingFlags.Public);

IntPtr nodeHandle = (System.IntPtr)nodeInfo.GetValue(node);

//Gets the treeview handle
node.TreeView.Capture = true;
IntPtr treeHandle = GetCapture();
node.TreeView.Capture = false;

//Sets the desired node state
TVITEM tvi = new TVITEM();
tvi.hItem = nodeHandle;
tvi.mask = TVIF_STATE;
tvi.stateMask = TVIS_STATEIMAGEMASK;
tvi.state = 0 << 12;

SendMessage(treeHandle, TVM_SETITEM, IntPtr.Zero, ref tvi);
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top