sjcu
asked on
How to handle KEY_DOWN and VK_SPACE bar messages in a TreeCntrl
I have a tree control in a dialog with check boxes. I am handling NM_CLICK when the
checkbox is changed. Now i need to be able to support accesiblitiy as well, so i have
to handle TVN_KEYDOWN messages to capture VK_SPACE and VK_RETURN.
The problem that i have is, i am not able to get a valid HTREEITEM. How to
get the valid one ?
LPNMTVKEYDOWN pTVKeyDown = reinterpret_cast<LPNMTVKEY DOWN>(pNMH DR);
if( ( pTVKeyDown->wVKey == VK_RETURN ) ||
( pTVKeyDown->wVKey == VK_SPACE ))
{
POINT pt;
UINT uFlags = 0;
::GetCursorPos(&pt);
m_treeCtrl.ScreenToClient( &pt);
HTREEITEM hItemNew = m_treeCtrl.HitTest(pt,&uFl ags);
m_Isdirty = TRUE;
OnClickAgentTree(pNMHDR, pResult);
}
This code however does not work.... Any thoughts on this one ....
Thanks in advance
checkbox is changed. Now i need to be able to support accesiblitiy as well, so i have
to handle TVN_KEYDOWN messages to capture VK_SPACE and VK_RETURN.
The problem that i have is, i am not able to get a valid HTREEITEM. How to
get the valid one ?
LPNMTVKEYDOWN pTVKeyDown = reinterpret_cast<LPNMTVKEY
if( ( pTVKeyDown->wVKey == VK_RETURN ) ||
( pTVKeyDown->wVKey == VK_SPACE ))
{
POINT pt;
UINT uFlags = 0;
::GetCursorPos(&pt);
m_treeCtrl.ScreenToClient(
HTREEITEM hItemNew = m_treeCtrl.HitTest(pt,&uFl
m_Isdirty = TRUE;
OnClickAgentTree(pNMHDR, pResult);
}
This code however does not work.... Any thoughts on this one ....
Thanks in advance
ASKER
Thanks. It works. I also need to get the pFlags.... As in my code i have a check for (uFlags & TVHT_ONITEM).
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for the fast response
You can just query the tree for what item has the selection as this code snippet shows
HTREEITEM hItem = GetSelectedItem();
if(hItem == NULL)
return NULL; //Nothing selected