15 мая 2023 года "Исходники.РУ" отмечают своё 23-летие!
Поздравляем всех причастных и неравнодушных с этим событием!
И огромное спасибо всем, кто был и остаётся с нами все эти годы!

Главная Форум Журнал Wiki DRKB Discuz!ML Помощь проекту


TreeCtrl HitTest problem

Ted -- tward@geographix.com
Tuesday, August 06, 1996

Environment:  WINNT4.0 beta 2, MSVC 4.1

CTreeStateDlg is CDialog derived.
m_Tree is a valid CTreeCtrl.

My trace statement is always "nowhere", and hItem is always NULL..  Any 
ideas?

void CTreeStateDlg::OnClickTree1(NMHDR* pNMHDR, LRESULT* pResult) 
{

	UINT Flags;
	CPoint Point;

	::GetCursorPos(&Point);
	ScreenToClient(&Point);

	HTREEITEM hItem = m_Tree.HitTest(Point,&Flags);

	if (TVHT_ABOVE & Flags)
		TRACE ("Above\n");
	if (TVHT_BELOW & Flags)
		TRACE ("below\n");
	if (TVHT_NOWHERE   & Flags)
		TRACE ("nowhere\n");		// This is the only message I get.
	if (TVHT_ONITEM    & Flags)
		TRACE ("on\n");
	if (TVHT_ONITEMBUTTON    & Flags)
		TRACE ("on button\n");
	if (TVHT_ONITEMICON    & Flags)
		TRACE ("on icon\n");
	if (TVHT_ONITEMINDENT  & Flags)
		TRACE ("on indent\n");
	if (TVHT_ONITEMLABEL   & Flags)
		TRACE ("on label\n");
	if (TVHT_ONITEMRIGHT   & Flags)
		TRACE ("on right\n");
	if (TVHT_ONITEMSTATEICON    & Flags)
		TRACE ("on stateicon\n");
	if (TVHT_TOLEFT    & Flags)
		TRACE ("to left\n");
	if (TVHT_TORIGHT   & Flags)
		TRACE ("to right\n");
}



R.H.J. Geraets -- R.Geraets@Ehv.Tass.Philips.Com
Friday, August 09, 1996

[Moderator's note: There were 10 responses, all essentially the same as
this first one.]

At 09:18 8/6/96 -0600, you wrote:
>Environment:  WINNT4.0 beta 2, MSVC 4.1
>
>CTreeStateDlg is CDialog derived.
>m_Tree is a valid CTreeCtrl.
>
>My trace statement is always "nowhere", and hItem is always NULL..  Any 
>ideas?
>
>void CTreeStateDlg::OnClickTree1(NMHDR* pNMHDR, LRESULT* pResult) 
>{
>
>	UINT Flags;
>	CPoint Point;
>
>	::GetCursorPos(&Point);
>	ScreenToClient(&Point);
>
>	HTREEITEM hItem = m_Tree.HitTest(Point,&Flags);

> [....]
>
>	if (TVHT_NOWHERE   & Flags)
>		TRACE ("nowhere\n");		// This is the only message I get.
> [....]


Use
  m_Tree.ScreenToClient(&Point);
to convert the screen coordinates to window coordiantes of the tree control.
By calling ScreenToClient(&Point) the coordiantes are converted relative
to the dialog, they need to be converted relative to your tree control.

Hope this helps,

Rene' Geraets




| Вернуться в корень Архива |