cursor position

is there a way with the CListCtr control to find out what the cursor postition is?
LVL 2
simongodAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Vinayak KumbarSr Program ManagerCommented:
Hi,

pls can u explain what exactly u want?
0
Vinayak KumbarSr Program ManagerCommented:
Hi,

Are u using vc++ 5.0 or vc++ 6.0?
0
Vinayak KumbarSr Program ManagerCommented:
Hi,

If I have understood correctly, U want the item and sub item where in mouse cursor is moving on the list control.

For that,
1. Derive Ur own class say CVinListCtrl from CListCtrl and     associate it with Ur list control
2. Trap the MouseMove() for that class and place the following     code

void VinListCtrl::OnMouseMove(UINT nFlags, CPoint point)
{
LVHITTESTINFO SubHitTest;
SubHitTest.pt = point;
ListView_SubItemHitTest(this->GetSafeHwnd(), &SubHitTest);
if(SubHitTest.iItem != -1)
{
     CString str;
     str.Format("%d, %d", SubHitTest.iItem+1,                                       SubHitTest.iSubItem+1);
     SetItemText(0,0,str);
}
CListCtrl::OnMouseMove(nFlags, point);
}

It will display the posion of the mouse in terms of item and subitem in first row and first col. For this to work, the items should be inserted in the list control.

hope that helps.

VinExpert
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Rowby Goren Makes an Impact on Screen and Online

Learn about longtime user Rowby Goren and his great contributions to the site. We explore his method for posing questions that are likely to yield a solution, and take a look at how his career transformed from a Hollywood writer to a website entrepreneur.

simongodAuthor Commented:
i am using vc 6, When I select an item in the ListCtrl I want that Item to be displayed in an edit box.
0
Vinayak KumbarSr Program ManagerCommented:
Hi,

No Prob...

Follow the same procedure, but instead of mapping WM_MOUSEMOVE, map WM_LBUTTONDOWN massage and put the code as bellow

void VinListCtrl::OnLButtonDown(UINT nFlags, CPoint point)
{
LVHITTESTINFO SubHitTest;
SubHitTest.pt = point;
ListView_SubItemHitTest(this->GetSafeHwnd(), &SubHitTest);
if(SubHitTest.iItem != -1)
{
CString str;
str.Format("%d, %d", SubHitTest.iItem+1,                SubHitTest.iSubItem+1);
this->GetParent()->GetDlgItem(IDC_EDIT1)->SetWindowText(str);
}
CListCtrl::OnLButtonDown(nFlags, point);
}
---------------------
OR
---------------------
U can map the NM_CLICK message to trap the OnClick() function.

That function will look like

void VinListCtrl::OnClick(NMHDR* pNMHDR, LRESULT* pResult)
{
NMLISTVIEW      *listinfo = (NMLISTVIEW *)pNMHDR;
CString str;
str.Format(" %d, %d", listinfo->iItem+1, listinfo->iSubItem+1);
this->GetParent()->GetDlgItem(IDC_EDIT1)->SetWindowText(str);
*pResult = 0;
}

Hope this helps.

VinExpert
0
simongodAuthor Commented:
i figured it out for myself.  your stuff did work though.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.