Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CListCtrl::HitTest....Whats the Point?

Status
Not open for further replies.

ncwizad

Programmer
Aug 25, 2005
10
GB
Hi.
My CListCtrl is called m_List, which i've populated with some data. i've added an event (NM_CLICK) with the expectation that i could use HitTest to determine which row number was highlighted. The code is as follows...

void CTls2csvDlg::OnClickList(NMHDR* pNMHDR, LRESULT* pResult)
{
CPoint mypoint;
UINT uFlags;
int pos1 = m_List.HitTest(mypoint, &uFlags);

// Write to status bar
sprintf(stat, "click Line Number = %i", pos1);
SendDlgItemMessage( IDC_STATUS, SB_SETTEXT, 0,
(LPARAM)stat);
UpdateData(FALSE);

*pResult = 0;
}

All that gets sent to the status bar is -1.
i'm obviously doing something totally stupid, but can someone please give me a clue?
Thanks in Advance
Dave H.
 
More Info........
The problem seems to lie with the CPoint class, as the x and y values of the picked position are not being passed along. What do i need to do to get these values to the HitTest proc???
Dave H
 
OK I get it!, the HitTest doesnt work
I've had to create my own function to do its job
Code:
void CTls2csvDlg::OnDblclkList(NMHDR* pNMHDR, LRESULT* pResult) 
{
	
		int pos1 = GetPickedItem();

		sprintf(stat,"Editing %s",  m_List.GetItemText( pos1,0)  );
	SendDlgItemMessage( IDC_STATUS, SB_SETTEXT, 0, 
	(LPARAM)stat);

	char debug[50]={'\0'};
	sprintf(debug,"%s",m_List.GetItemText( pos1,0) );	
	MessageBox(debug,"Debug Message",MB_ICONEXCLAMATION);


	*pResult = 0;
}


int CTls2csvDlg::GetPickedItem()
{
    int nItem = -1;
    POSITION nPos = m_List.GetFirstSelectedItemPosition();
    if (nPos)
    {
        nItem = m_List.GetNextSelectedItem(nPos);
    }
    return nItem;
	
}
This works ok to select the row, but how do i select tyhe column.
ps You can join in any time you know!
 
1)

>The problem seems to lie with the CPoint class, as the x and y values of the picked position are not being passed along.

Well you never assign the CPoint anything - so how would it know what to pass along? Besides, NM_CLICK just notifies that you've clicked it doesn't say exactly where.

You could have your control catch WM_MOUSEMOVE messages and update a CPoint member. Then at least you'd have the last known mouse coordinate.


2)
Code:
m_List.HitTest(mypoint, &uFlags);

The HitTest you use is only used in returning the flags. Have you tried using the other signature?

Code:
int HitTest( LVHITTESTINFO* pHitTestInfo ) const;


/Per

www.perfnurt.se
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top