Notifications
Clear all
[Closed] Some tricks with TreeView Label Edit
Nov 30, 2010 4: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;
"
source += "using System.Windows.Forms;
"
source += "public class WindowHook : NativeWindow
"
source += "{
"
source += " private const int WM_GETDLGCODE = 0x0087;
"
source += " private const int DLGC_WANTALLKEYS = 0x0004;
"
source += " public WindowHook() { }
"
source += " protected override void WndProc(ref Message m)
"
source += " {
"
source += " switch (m.Msg)
"
source += " {
"
source += " case WM_GETDLGCODE:
"
source += " m.Result = (IntPtr)DLGC_WANTALLKEYS;
"
source += " break;
"
source += " default:
"
source += " base.WndProc(ref m);
"
source += " break;
"
source += " }
"
source += " }
"
source += "}
"
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.
4 Replies
Nov 30, 2010 4:38 pm
That’s like hacky workaround poetry, man :applause:
May I ask how do you know which windows message codes do what?
1 Reply
I feel it ;)…
First, I just know that a message has to be. Second, I find the right one. Third, I read a documentation. If the message is wrong I repeat the second and the third steps again ;). The number of iterations depends on how lucky I am.