lily1102
asked on
HOW TO GET THE MOUSE POINT BY DOUBLE CLICKING
I have tried to implement the editable CListCtrl by browsing some solutions on the internet.
In one solution, it coded:
void CEditableList::OnLButtonDb lClk(UINT nFlags, CPoint point)
{
......
}
The parameter point is needed for the implementation.
However, my object of CListCtrl does not have the double clicking fucntion looks like above.
Mine is:
void SAMPLE_DLG::OnDblclkSample List(NMHDR * pNMHDR, LRESULT* pResult)
where SampleList is the object name of the CListCtrl.
If I use the double-clicking function of the Dialog that contains the SampleList, it does has the thing that I need, which is void SAMPLE_DLG::OnLButtonDblCl k(UINT nFlags, CPoint point) .
However, if I run it, and double click on the SampleList, SAMPLE_DLG::OnLButtonDblCl k(...) is not executed. if I double click on any other area not on SampleList, SAMPLE_DLG::OnLButtonDblCl k(...) is executed.
My question is that how to get the point while I double click on SampleList. Thanks.
In one solution, it coded:
void CEditableList::OnLButtonDb
{
......
}
The parameter point is needed for the implementation.
However, my object of CListCtrl does not have the double clicking fucntion looks like above.
Mine is:
void SAMPLE_DLG::OnDblclkSample
where SampleList is the object name of the CListCtrl.
If I use the double-clicking function of the Dialog that contains the SampleList, it does has the thing that I need, which is void SAMPLE_DLG::OnLButtonDblCl
However, if I run it, and double click on the SampleList, SAMPLE_DLG::OnLButtonDblCl
My question is that how to get the point while I double click on SampleList. Thanks.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
There are a few ways to achieve what you want.
The first you should try is to activate the VC6 wizard - CTRL+W -, choose the list control and add a handler for the NM_DBLCLK message. You should get a function like
void CTestDlg::OnNMDblclkList1( NMHDR *pNMHDR, LRESULT *pResult)
{
// todo: ...
*pResult = 0;
}
Unfortunately the pNMHDR doesn't tell you where the user has clicked. First you should try to *cast* the NMHDR struct to a NMLISTVIEW struct by
LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTV IEW>(pNMHD R);
(I mean I successfully have done that a few years ago).
If successful the iItem and iSubItem member of the NMLISTVIEW should be valid and tell what you need to know.
If the members were garbage or both 0 you could retrieve the mouse position by GetCursorPos, transfer the windows coordinates to client coordianets and call the CListCtrl::HitTest to determine the cell where the use has clicked. Tell me if you need help for that.
The first you should try is to activate the VC6 wizard - CTRL+W -, choose the list control and add a handler for the NM_DBLCLK message. You should get a function like
void CTestDlg::OnNMDblclkList1(
{
// todo: ...
*pResult = 0;
}
Unfortunately the pNMHDR doesn't tell you where the user has clicked. First you should try to *cast* the NMHDR struct to a NMLISTVIEW struct by
LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTV
(I mean I successfully have done that a few years ago).
If successful the iItem and iSubItem member of the NMLISTVIEW should be valid and tell what you need to know.
If the members were garbage or both 0 you could retrieve the mouse position by GetCursorPos, transfer the windows coordinates to client coordianets and call the CListCtrl::HitTest to determine the cell where the use has clicked. Tell me if you need help for that.
ASKER
Thanks for all.
I use alb66's comment and it works great.
I use alb66's comment and it works great.
ASKER
You are perfect.
CListCtrl is derived from CWnd which has the OnLButtonDblClk member method http://msdn.microsoft.com/en-us/library/3efhe03w(VS.80).aspx so you would have to add the method to the custom CListCtrl derived class of SampleList if there is one, e.g.:
// .h of CListCtrl derived class, the data type of SampleList
afx_msg void OnLButtonDblClk(UINT nFlags, CPoint point);
// .cpp of CListCtrl derived class, the data type of SampleList
void SampleListClass::OnLButton
{
// To do code
CWnd::OnLButtonDblClk(nFla
}