-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathFolderBrowserDialogObject.cs
More file actions
120 lines (98 loc) · 3.34 KB
/
FolderBrowserDialogObject.cs
File metadata and controls
120 lines (98 loc) · 3.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
// Set a folder view at any subdirectory eg e:\Windows
//
// Create a new form in your project - call it FolderViewRoot
// edit the FolderViewRoot.cs and paste the contents of this file in.
//
// to use on your program use the following code
//
// - FolderViewRoot secondForm = new FolderViewRoot();
// - secondForm.FVrootdirectory = "c:\ATI";
// - secondForm.FVrootdirectorylable = "Select Media Directory";
// - secondForm.Show();
// -
// - // returns string in FVrootdirectoryfull
// - MessageBox.Show(secondForm.FVrootdirectoryfull);
//
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
namespace KimeraCS
{
using static User32;
public class FolderBrowserDialogEX
{
// -----------------------------------------------------------------------------
// Helper for FolderBrowserDialog object.
// -----------------------------------------------------------------------------
public FolderBrowserDialog folderBrowser;
public bool Disposed { get; private set; }
public FolderBrowserDialogEX()
{
Tmr = new Timer() { Interval = 200 };
folderBrowser = new FolderBrowserDialog();
}
public void Dispose()
{
if (Disposed) return;
Disposed = true;
Tmr.Dispose();
folderBrowser.Dispose();
}
private Timer _Tmr;
public Timer Tmr
{
[MethodImpl(MethodImplOptions.Synchronized)]
get
{
return _Tmr;
}
[MethodImpl(MethodImplOptions.Synchronized)]
set
{
if (_Tmr != null)
{
_Tmr.Tick -= Tmr_Tick;
}
_Tmr = value;
if (_Tmr != null)
{
_Tmr.Tick += Tmr_Tick;
}
}
}
private const int WM_USER = 1024;
private const int BFFM_SETEXPANDED = (WM_USER + 106);
private const int WM_SETFOCUS = 7;
private const int WM_SETREDRAW = 11;
public void Tmr_Tick(object sender, System.EventArgs e)
{
// Dim hFb As IntPtr = FindWindowExW(IntPtr.Zero, IntPtr.Zero, "#32770", Nothing)
IntPtr hFb = GetActiveWindow();
SendMessage(hFb, WM_SETREDRAW, false, 0);
if ((hFb != IntPtr.Zero))
{
IntPtr hChild = FindWindowExW(hFb, IntPtr.Zero, null, null);
IntPtr hTreeView = FindWindowExW(hChild, IntPtr.Zero, "SysTreeView32", null);
while ((hTreeView == IntPtr.Zero))
{
hChild = FindWindowExW(hFb, hChild, null, null);
hTreeView = FindWindowExW(hChild, IntPtr.Zero, "SysTreeView32", null);
}
if (SendMessageW(hFb, BFFM_SETEXPANDED, 1, folderBrowser.SelectedPath) == IntPtr.Zero)
{
Tmr.Stop();
SendMessageW(hTreeView, WM_SETFOCUS, 0, null);
}
}
SendMessage(hFb, WM_SETREDRAW, true, 0);
}
}
}