denisT
11-30-2010, 03:38 PM
here is a sample that shows how to make a custom tree view Label editing, force to support ENTER and ESC, and make some labels are READ ONLY:
fn CreateNativeWindowOps forceRecompile:on = if forceRecompile do
(
source = ""
source += "using System;\n"
source += "using System.Windows.Forms;\n"
source += "public class WindowHook : NativeWindow\n"
source += "{\n"
source += " private const int WM_GETDLGCODE = 0x0087;\n"
source += " private const int DLGC_WANTALLKEYS = 0x0004;\n"
source += " public WindowHook() { }\n"
source += " protected override void WndProc(ref Message m)\n"
source += " {\n"
source += " switch (m.Msg)\n"
source += " {\n"
source += " case WM_GETDLGCODE:\n"
source += " m.Result = (IntPtr)DLGC_WANTALLKEYS;\n"
source += " break;\n"
source += " default:\n"
source += " base.WndProc(ref m);\n"
source += " break;\n"
source += " }\n"
source += " }\n"
source += "}\n"
csharpProvider = dotnetobject "Microsoft.CSharp.CSharpCodeProvider"
compilerParams = dotnetobject "System.CodeDom.Compiler.CompilerParameters"
compilerParams.ReferencedAssemblies.AddRange #("System.dll", "System.Windows.Forms.dll")
compilerParams.GenerateInMemory = true
compilerResults = csharpProvider.CompileAssemblyFromSource compilerParams #(source)
global NativeWindowOps = compilerResults.CompiledAssembly
)
CreateNativeWindowOps()
try(destroydialog tv_rol) catch()
rollout tv_rol "TreeView Test" width:200 height:200
(
local hook = dotnetobject "WindowHook"
dotnetcontrol tv "TreeView" width:200 height:200 pos:[0,0]
on tv NodeMouseDoubleClick s e do
(
s.LabelEdit = on
e.node.BeginEdit()
)
on tv AfterLabelEdit s e do
(
hook.ReleaseHandle()
s.LabelEdit = off
)
on tv BeforeLabelEdit s e do
(
TVM_GETEDITCONTROL = 0x110F
hwnd = windows.SendMessage s.Handle TVM_GETEDITCONTROL 0 0
hook.AssignHandle (dotnetobject "IntPtr" hwnd)
if e.node.text == "read only" do
(
EM_SETREADONLY = 0x00CF
windows.SendMessage hwnd EM_SETREADONLY 1 0
)
)
on tv_rol open do
(
tv.LabelEdit = off
for node in #("read only", "edit1", "edit2") do tv.nodes.Add node
)
)
createdialog tv_rol
as I have a time I will post a brief explanation how it works.
fn CreateNativeWindowOps forceRecompile:on = if forceRecompile do
(
source = ""
source += "using System;\n"
source += "using System.Windows.Forms;\n"
source += "public class WindowHook : NativeWindow\n"
source += "{\n"
source += " private const int WM_GETDLGCODE = 0x0087;\n"
source += " private const int DLGC_WANTALLKEYS = 0x0004;\n"
source += " public WindowHook() { }\n"
source += " protected override void WndProc(ref Message m)\n"
source += " {\n"
source += " switch (m.Msg)\n"
source += " {\n"
source += " case WM_GETDLGCODE:\n"
source += " m.Result = (IntPtr)DLGC_WANTALLKEYS;\n"
source += " break;\n"
source += " default:\n"
source += " base.WndProc(ref m);\n"
source += " break;\n"
source += " }\n"
source += " }\n"
source += "}\n"
csharpProvider = dotnetobject "Microsoft.CSharp.CSharpCodeProvider"
compilerParams = dotnetobject "System.CodeDom.Compiler.CompilerParameters"
compilerParams.ReferencedAssemblies.AddRange #("System.dll", "System.Windows.Forms.dll")
compilerParams.GenerateInMemory = true
compilerResults = csharpProvider.CompileAssemblyFromSource compilerParams #(source)
global NativeWindowOps = compilerResults.CompiledAssembly
)
CreateNativeWindowOps()
try(destroydialog tv_rol) catch()
rollout tv_rol "TreeView Test" width:200 height:200
(
local hook = dotnetobject "WindowHook"
dotnetcontrol tv "TreeView" width:200 height:200 pos:[0,0]
on tv NodeMouseDoubleClick s e do
(
s.LabelEdit = on
e.node.BeginEdit()
)
on tv AfterLabelEdit s e do
(
hook.ReleaseHandle()
s.LabelEdit = off
)
on tv BeforeLabelEdit s e do
(
TVM_GETEDITCONTROL = 0x110F
hwnd = windows.SendMessage s.Handle TVM_GETEDITCONTROL 0 0
hook.AssignHandle (dotnetobject "IntPtr" hwnd)
if e.node.text == "read only" do
(
EM_SETREADONLY = 0x00CF
windows.SendMessage hwnd EM_SETREADONLY 1 0
)
)
on tv_rol open do
(
tv.LabelEdit = off
for node in #("read only", "edit1", "edit2") do tv.nodes.Add node
)
)
createdialog tv_rol
as I have a time I will post a brief explanation how it works.
