diff --git a/NBTExplorer/Interop.cs b/NBTExplorer/Interop.cs new file mode 100644 index 0000000..2be1bdd --- /dev/null +++ b/NBTExplorer/Interop.cs @@ -0,0 +1,64 @@ +using System; +using System.Runtime.InteropServices; + +namespace NBTExplorer +{ + internal static class Interop + { + public static bool WinInteropAvailable + { + get { return IsWindows && Type.GetType("Mono.Runtime") == null; } + } + + public static bool IsWindows + { + get { return Environment.OSVersion.Platform == PlatformID.Win32NT; } + } + + public static bool IsWinXP + { + get + { + OperatingSystem OS = Environment.OSVersion; + return (OS.Platform == PlatformID.Win32NT) && + ((OS.Version.Major > 5) || ((OS.Version.Major == 5) && (OS.Version.Minor == 1))); + } + } + + public static bool IsWinVista + { + get + { + OperatingSystem OS = Environment.OSVersion; + return (OS.Platform == PlatformID.Win32NT) && (OS.Version.Major >= 6); + } + } + + public static IntPtr SendMessage (IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam) + { + if (WinInteropAvailable) + return NativeInterop.SendMessage(hWnd, msg, wParam, lParam); + else + return IntPtr.Zero; + } + } + + internal static class NativeInterop + { + public const int WM_PRINTCLIENT = 0x0318; + public const int PRF_CLIENT = 0x00000004; + + public const int TV_FIRST = 0x1100; + public const int TVM_SETBKCOLOR = TV_FIRST + 29; + public const int TVM_SETEXTENDEDSTYLE = TV_FIRST + 44; + + public const int TVS_EX_DOUBLEBUFFER = 0x0004; + + [DllImport("user32.dll")] + public static extern IntPtr SendMessage (IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam); + + + + + } +} diff --git a/NBTExplorer/NBTExplorer.csproj b/NBTExplorer/NBTExplorer.csproj index d172dc9..8a70f8b 100644 --- a/NBTExplorer/NBTExplorer.csproj +++ b/NBTExplorer/NBTExplorer.csproj @@ -12,6 +12,7 @@ NBTExplorer v2.0 512 + false publish\ true Disk @@ -24,7 +25,6 @@ true 0 1.0.0.%2a - false false true @@ -100,6 +100,7 @@ + diff --git a/NBTExplorer/Vendor/MultiSelectTreeView/MultiSelectTreeview.cs b/NBTExplorer/Vendor/MultiSelectTreeView/MultiSelectTreeview.cs index db22de9..217a4a7 100644 --- a/NBTExplorer/Vendor/MultiSelectTreeView/MultiSelectTreeview.cs +++ b/NBTExplorer/Vendor/MultiSelectTreeView/MultiSelectTreeview.cs @@ -11,7 +11,6 @@ namespace NBTExplorer.Vendor.MultiSelectTreeView { public class MultiSelectTreeView : TreeView { - #region Selected Node(s) Properties private List m_SelectedNodes = null; @@ -57,14 +56,40 @@ namespace NBTExplorer.Vendor.MultiSelectTreeView public MultiSelectTreeView() { + DoubleBuffered = true; + SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint, true); m_SelectedNodes = new List(); base.SelectedNode = null; } + private void UpdateExtendedStyles () + { + if (Interop.WinInteropAvailable) { + int style = 0; + + if (DoubleBuffered) + style |= NativeInterop.TVS_EX_DOUBLEBUFFER; + + if (style != 0) + Interop.SendMessage(Handle, NativeInterop.TVM_SETEXTENDEDSTYLE, (IntPtr)NativeInterop.TVS_EX_DOUBLEBUFFER, (IntPtr)style); + } + } + #region Overridden Events + protected override void OnHandleCreated (EventArgs e) + { + base.OnHandleCreated(e); + + if (Interop.WinInteropAvailable) { + UpdateExtendedStyles(); + if (!Interop.IsWinXP) + Interop.SendMessage(Handle, NativeInterop.TVM_SETBKCOLOR, IntPtr.Zero, (IntPtr)ColorTranslator.ToWin32(BackColor)); + } + } + protected override void OnGotFocus( EventArgs e ) { // Make sure at least one node has a selection