TreeViewからTVN_SELCHANGINGメッセージをキャッチしようとしています。BeforeSelectイベントもあることは知っていますが、メッセージをキャッチできない理由を理解したいと思います…</ p>
私はmsdnでTVN_SELCHANG(ED)(ING)を読みました。LParamはNMTREEVIEW構造体へのポインターです。また、コードはWM_NOTIFYメッセージの形式で送信されます。
だから私はそれを実装しようとしました:( これは私を助けました)
public partial class TreeviewEx : TreeView
{
[StructLayout(LayoutKind.Sequential)]
public struct POINT
{
public int X;
public int Y;
}
[StructLayout(LayoutKind.Sequential)]
private struct TVITEM
{
public uint mask;
public IntPtr hItem;
public uint state;
public uint stateMask;
public IntPtr pszText;
public int cchTextMax;
public int iImage;
public int iSelectedImage;
public int cChildren;
public IntPtr lParam;
}
[StructLayout(LayoutKind.Sequential)]
private struct NMHDR
{
public IntPtr hwndFrom;
public IntPtr idFrom;
public int code;
}
[StructLayout(LayoutKind.Sequential)]
private struct NMTREEVIEW
{
public NMHDR hdr;
public int action;
public TVITEM itemOld;
public TVITEM itemNew;
public POINT ptDrag;
}
private const int TVN_FIRST = -400;
private const int TVN_SELCHANGINGA = (TVN_FIRST - 1);
private const int TVN_SELCHANGINGW = (TVN_FIRST - 50);
private const int TVN_SELCHANGEDA = (TVN_FIRST - 2);
private const int TVN_SELCHANGEDW = (TVN_FIRST - 51);
private const int WM_NOTIFY = 0x004e;
protected override void WndProc(ref Message m)
{
if (m.Msg == WM_NOTIFY)
{
var notify = (NMTREEVIEW)Marshal.PtrToStructure(m.LParam, typeof(NMTREEVIEW));
if (notify.action == TVN_SELCHANGINGA)
{
MessageBox.Show("changing");
}
}
base.WndProc(ref m);
}
私はすべてのアクションを試しましたが、どれも機能していないようです。私は何が間違っているのですか?