PDA

View Full Version : Some tricks with TreeView Label Edit


denisT
11-30-2010, 04: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.

lo
11-30-2010, 05:24 PM
That's like hacky workaround poetry, man :applause:

May I ask how do you know which windows message codes do what?

denisT
11-30-2010, 05:37 PM
May I ask how do you know which windows message codes do what?

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.

Kameleon
11-30-2010, 05:58 PM
Also, after some googling : http://support.microsoft.com/kb/130691/

DaveWortley
11-30-2010, 07:06 PM
DenisT, you are some kind of evil genius...

Many thanks for this....

CGTalk Moderation
11-30-2010, 07:06 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.