我使用CTreeCtrl
,并且我想要捕获TVN_SELCHANGING
事件。如果我使用一个选择,则运行TVN_SELCHANGING
。但如果我设置TVS_EX_MULTISELECT
ex_style,则不处理TVN_SELCHANGING
。
原因是什么?该怎么办?
TVS_EX_MULTISELECT
样式可防止由于未知原因发送TVN_SELCHANGING
。
然而,TVN_ITEMCHANGING
被发送,您可以在自己的窗口程序中使用它来伪造TVN_SELCHANGING
:
...
case TVN_ITEMCHANGING:
{
NMTVITEMCHANGE*pTVIC = (NMTVITEMCHANGE*) lParam;
if (pTVIC->uChanged == TVIF_STATE && ((pTVIC->uStateOld ^ pTVIC->uStateNew) & TVIS_SELECTED) && (TreeView_GetExtendedStyle(pTVIC->hdr.hwndFrom) & TVS_EX_MULTISELECT))
{
static HTREEITEM old = 0;
if (pTVIC->uStateNew & TVIS_SELECTED)
{
UINT mask = TVIF_IMAGE|TVIF_SELECTEDIMAGE|TVIF_PARAM|TVIF_STATE;
NMTREEVIEW nmtv = { };
nmtv.hdr = pTVIC->hdr, nmtv.hdr.code = TVN_SELCHANGING, nmtv.action = TVC_UNKNOWN;
TreeView_GetItem(pTVIC->hdr.hwndFrom, (nmtv.itemNew.hItem = pTVIC->hItem, nmtv.itemNew.mask = mask, &nmtv.itemNew));
if (old) TreeView_GetItem(pTVIC->hdr.hwndFrom, (nmtv.itemOld.hItem = old, nmtv.itemOld.mask = mask, &nmtv.itemOld));
SendMessage(GetParent(pTVIC->hdr.hwndFrom), WM_NOTIFY, pTVIC->hdr.idFrom, (LPARAM) &nmtv);
old = 0;
}
else
{
old = pTVIC->hItem; // Note: This assumes the de-selection item change message is sent before the selection item change message!
}
}
}
break;
...