RaUI/Source/ryControls/Sheng.Winform.Controls/Win32/ExplorerTreeView.cs
鑫Intel c3d4ddf574 ### 2021-07-29更新
------
#### MyDbV4   V3.0.2107.2901
- *.[新增]新增支持计算文件MD5。
- *.[新增]部分DataProvider功能移植到DbExtension里,增加扩展性。
- *.[新增]UnixTimeToDateTime和JSTimeToDateTime新增支持long参数。
- *.[合并]合并RyWeb项目到MyDb里。

#### ryControlsV4    V3.0.2107.2901
  -  *.[改进]优化减少大量IDE警告和消息。
2021-07-29 17:09:32 +08:00

72 lines
2.5 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace Sheng.Winform.Controls.Win32
{
/// <summary>
///
/// </summary>
public class ExplorerTreeView
{
const int TV_FIRST = 0x1100;
const int TVM_SETEXTENDEDSTYLE = TV_FIRST + 44;
const int TVM_GETEXTENDEDSTYLE = TV_FIRST + 45;
const int TVS_EX_FADEINOUTEXPANDOS = 0x0040;
const int TVS_EX_DOUBLEBUFFER = 0x0004;
/// <summary>
///
/// </summary>
/// <param name="hWnd"></param>
/// <param name="subAppName"></param>
/// <param name="subIdList"></param>
/// <returns></returns>
[DllImport("uxtheme.dll", CharSet = CharSet.Auto)]
public extern static int SetWindowTheme(IntPtr hWnd, string subAppName, string subIdList);
/// <summary>
///
/// </summary>
/// <param name="hWnd"></param>
/// <param name="Msg"></param>
/// <param name="wParam"></param>
/// <param name="lParam"></param>
/// <returns></returns>
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public extern static IntPtr SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, IntPtr lParam);
private static int TreeView_GetExtendedStyle(IntPtr handle)
{
IntPtr ptr = SendMessage(handle, TVM_GETEXTENDEDSTYLE, IntPtr.Zero, IntPtr.Zero);
return ptr.ToInt32();
}
private static void TreeView_SetExtendedStyle(IntPtr handle, int extendedStyle, int mask)
{
SendMessage(handle, TVM_SETEXTENDEDSTYLE, new IntPtr(mask), new IntPtr(extendedStyle));
}
/// <summary>
/// Modify a WinForms TreeView control to use the new Explorer style theme
/// </summary>
/// <param name="treeView"></param>
public static void ApplyTreeViewThemeStyles(TreeView treeView)
{
if (treeView == null)
{
throw new ArgumentNullException("treeView");
}
treeView.HotTracking = true;
treeView.ShowLines = false;
IntPtr hwnd = treeView.Handle;
SetWindowTheme(hwnd, "Explorer", null);
int exstyle = TreeView_GetExtendedStyle(hwnd);
exstyle |= TVS_EX_DOUBLEBUFFER | TVS_EX_FADEINOUTEXPANDOS;
TreeView_SetExtendedStyle(hwnd, exstyle, 0);
}
}
}