Created
June 16, 2010 02:05
-
-
Save chrisforbes/440030 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static class VariableHeightItems | |
{ | |
[DllImport("user32")] | |
static extern IntPtr SendMessage(IntPtr hwnd, uint msg, IntPtr wp, IntPtr lp); | |
[StructLayout(LayoutKind.Sequential)] | |
struct TVITEMEX | |
{ | |
public Mask mask; | |
public IntPtr item; | |
public uint state; | |
public uint stateMask; | |
public IntPtr pszText; | |
public int cchTextMax; | |
public int iImage; | |
public int iSelectedImage; | |
public int iChildren; | |
public IntPtr lParam; | |
public int iIntegral; | |
// ... plus some windows 6+ crap | |
} | |
[Flags] | |
enum Mask : uint | |
{ | |
Text = 1, | |
Image = 2, | |
Param = 4, | |
State = 8, | |
Handle = 16, | |
SelectedImage = 32, | |
Children = 64, | |
Integral = 128, | |
} | |
const int TVM_GETITEM = 0x1100 + 62; | |
const int TVM_SETITEM = 0x1100 + 63; | |
public static int GetHeight(this TreeNode tn) | |
{ | |
TVITEMEX tvix; | |
tvix.mask = Mask.Handle | Mask.Integral; | |
tvix.item = tn.Handle; | |
tvix.iIntegral = 0; | |
unsafe { SendMessage(tn.TreeView.Handle, TVM_GETITEM, IntPtr.Zero, new IntPtr((void*)&tvix)); } | |
return tvix.iIntegral; | |
} | |
public static void SetHeight(this TreeNode tn, int height) | |
{ | |
TVITEMEX tvix; | |
tvix.mask = Mask.Handle | Mask.Integral; | |
tvix.item = tn.Handle; | |
tvix.iIntegral = height; | |
unsafe { SendMessage(tn.TreeView.Handle, TVM_SETITEM, IntPtr.Zero, new IntPtr((void*)&tvix)); } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment