WTL学习三 树控件的右键处理

MainDlg.h  中加入映射 MESSAGE_HANDLER(WM_CONTEXTMENU, OnRClick) 


MainDlg.cpp 中定义如下

LRESULT CMainDlg::OnRClick(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& /*bHandled*/)
{

	int xPos = GET_X_LPARAM(lParam); 
	int yPos = GET_Y_LPARAM(lParam); 

	POINT point;
	point.x = xPos;
	point.y = yPos;
	m_Tree.ScreenToClient(&point);

	UINT test;
	HTREEITEM hti = m_Tree.HitTest(point, &test );

	if ( ( hti != NULL ) && ( test & TVHT_ONITEM ) )
	{		
		TCHAR s1[100];
		m_Tree.GetItemText(hti,s1,100);
		MessageBox(s1,_T(""));
		HTREEITEM htCur = m_Tree.GetSelectedItem();

		if ( hti != htCur )
		{			
			m_Tree.SelectItem(hti);
		}
	
	}
	return TRUE;
}

你可能感兴趣的:(WTL)