A
adam
Good morning and happy Tuesday to all.
I have the pleasure of changing our custom tree view (that has it's own
look _and_ scroll mechanism) to support our own scrollbars.
Ignoring the main reasons why we should not be doing this I am having
some trouble discovering when nodes are added.
Our friend reflector tells me that the only notification that flows from
the TreeNodeColleciton is TVM_* messages to the TreeView. I tried to
intercept these messages but the override TreeView::WndProc does not
yield any results, nor does my use of NativeWindow::WndProc
Any ideas?
adam
class BaseTreeView : TreeView
{
const int TV_FIRST = 0x110;
const int TVM_INSERTITEMA = (TV_FIRST + 0);
const int TVM_INSERTITEMW = (TV_FIRST + 50);
const int TVM_DELETEITEM = (TV_FIRST + 1);
const int TVM_EXPAND = (TV_FIRST + 2);
const int TVM_GETITEMA = (TV_FIRST + 12);
const int TVM_GETITEMW = (TV_FIRST + 62);
const int TVM_SETITEMA = (TV_FIRST + 13);
const int TVM_SETITEMW = (TV_FIRST + 63);
TreeViewNative m_native;
public BaseTreeView (){m_native = new TreeViewNative(this);}
protected override void WndProc(ref Message message)
{
TraceTreeViewMessage(message.Msg);
base.WndProc(message);
}
public static void TraceTreeViewMessage(int messageId)
{
switch (messageId)
{
case TVM_INSERTITEMA: Log("TVM_INSERTITEMA"); break;
case TVM_INSERTITEMW: Log("TVM_INSERTITEMW"); break;
case TVM_DELETEITEM: Log("TVM_DELETEITEM"); break;
case TVM_EXPAND: Log("TVM_EXPAND"); break;
case TVM_GETITEMA: Log("TVM_GETITEMA"); break;
case TVM_GETITEMW: Log("TVM_GETITEMW"); break;
case TVM_SETITEMA: Log("TVM_SETITEMA"); break;
case TVM_SETITEMW: Log("TVM_SETITEMW"); break;
/* SNIP and all the other less interesting messages. */
}
}
private static void Log(string s)
{
System.Diagnostics.Debug.WriteLine(s);
}
}
class TreeViewNative : NativeWindow
{
Control m_target;
public TreeViewNative(Control target)
{
m_target = target;
if (m_target.IsHandleCreated)
AssignHandle(m_target.Handle);
else
m_target.HandleCreated += new EventHandler(target_HandleCreated);
m_target.HandleDestroyed += new EventHandler(target_HandleDestroyed);
}
private void target_HandleCreated(object sender, EventArgs e)
{ AssignHandle(m_target.Handle); }
private void target_HandleDestroyed(object sender, EventArgs e)
{ReleaseHandle();}
protected override void WndProc(ref Message message)
{
BaseTreeView.TraceTreeViewMessage(message.Msg);
base.WndProc (ref m);
}
}
I have the pleasure of changing our custom tree view (that has it's own
look _and_ scroll mechanism) to support our own scrollbars.
Ignoring the main reasons why we should not be doing this I am having
some trouble discovering when nodes are added.
Our friend reflector tells me that the only notification that flows from
the TreeNodeColleciton is TVM_* messages to the TreeView. I tried to
intercept these messages but the override TreeView::WndProc does not
yield any results, nor does my use of NativeWindow::WndProc
Any ideas?
adam
class BaseTreeView : TreeView
{
const int TV_FIRST = 0x110;
const int TVM_INSERTITEMA = (TV_FIRST + 0);
const int TVM_INSERTITEMW = (TV_FIRST + 50);
const int TVM_DELETEITEM = (TV_FIRST + 1);
const int TVM_EXPAND = (TV_FIRST + 2);
const int TVM_GETITEMA = (TV_FIRST + 12);
const int TVM_GETITEMW = (TV_FIRST + 62);
const int TVM_SETITEMA = (TV_FIRST + 13);
const int TVM_SETITEMW = (TV_FIRST + 63);
TreeViewNative m_native;
public BaseTreeView (){m_native = new TreeViewNative(this);}
protected override void WndProc(ref Message message)
{
TraceTreeViewMessage(message.Msg);
base.WndProc(message);
}
public static void TraceTreeViewMessage(int messageId)
{
switch (messageId)
{
case TVM_INSERTITEMA: Log("TVM_INSERTITEMA"); break;
case TVM_INSERTITEMW: Log("TVM_INSERTITEMW"); break;
case TVM_DELETEITEM: Log("TVM_DELETEITEM"); break;
case TVM_EXPAND: Log("TVM_EXPAND"); break;
case TVM_GETITEMA: Log("TVM_GETITEMA"); break;
case TVM_GETITEMW: Log("TVM_GETITEMW"); break;
case TVM_SETITEMA: Log("TVM_SETITEMA"); break;
case TVM_SETITEMW: Log("TVM_SETITEMW"); break;
/* SNIP and all the other less interesting messages. */
}
}
private static void Log(string s)
{
System.Diagnostics.Debug.WriteLine(s);
}
}
class TreeViewNative : NativeWindow
{
Control m_target;
public TreeViewNative(Control target)
{
m_target = target;
if (m_target.IsHandleCreated)
AssignHandle(m_target.Handle);
else
m_target.HandleCreated += new EventHandler(target_HandleCreated);
m_target.HandleDestroyed += new EventHandler(target_HandleDestroyed);
}
private void target_HandleCreated(object sender, EventArgs e)
{ AssignHandle(m_target.Handle); }
private void target_HandleDestroyed(object sender, EventArgs e)
{ReleaseHandle();}
protected override void WndProc(ref Message message)
{
BaseTreeView.TraceTreeViewMessage(message.Msg);
base.WndProc (ref m);
}
}