Solved

HOW TO GET THE MOUSE POINT BY DOUBLE CLICKING

Posted on 2008-10-22
5
530 Views
Last Modified: 2013-11-20
I have tried to implement the editable CListCtrl by browsing some solutions on the internet.
In one solution, it coded:
void CEditableList::OnLButtonDblClk(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::OnDblclkSampleList(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::OnLButtonDblClk(UINT nFlags, CPoint point) .
However, if I run it, and double click on the SampleList, SAMPLE_DLG::OnLButtonDblClk(...) is not executed. if I double click on any other area not on SampleList, SAMPLE_DLG::OnLButtonDblClk(...) is executed.
My question is that how to get the point while I double click on SampleList. Thanks.
0
Comment
Question by:lily1102
5 Comments
 
LVL 19

Expert Comment

by:LordOfPorts
ID: 22781851
Is SAMPLE_DLG derived from CListCtrl? By its name it sound as if it is a perhaps derived from dialog and represents the surrounding dialog view perhaps and not a class derived from CListCtrl?

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::OnLButtonDblClk(UINT nFlags, CPoint point)
{
    // To do code

   CWnd::OnLButtonDblClk(nFlags, point);
}




0
 
LVL 19

Accepted Solution

by:
alb66 earned 125 total points
ID: 22783627
It should be the following:

void SAMPLE_DLG::OnDblclkSampleList(NMHDR* pNMHDR, LRESULT* pResult)
{
  LPNMITEMACTIVATE lpnmitem = (LPNMITEMACTIVATE)pNMHDR;

  lpnmitem->iItem;               <------ row
  lpnmitem->iSubItem;         <------ column
  lpnmitem->ptAction;          <------ point

  ...

  *pResult = 0;
}

For greater details give a look at
http://msdn.microsoft.com/en-us/library/bb774867(VS.85).aspx
http://msdn.microsoft.com/en-us/library/bb774771(VS.85).aspx
0
 
LVL 39

Expert Comment

by:itsmeandnobodyelse
ID: 22783860
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<LPNMLISTVIEW>(pNMHDR);

(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.


 

0
 

Author Comment

by:lily1102
ID: 22788661
Thanks for all.
I use alb66's comment and it works great.
0
 

Author Closing Comment

by:lily1102
ID: 31508968
You are perfect.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Different colored text in ComboBox without Subclassing 8 55
xyBalance chalenge 58 88
Prevent this page from creating additional dialogs. 3 388
twoTwo  challenge 35 92
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Concerto provides fully managed cloud services and the expertise to provide an easy and reliable route to the cloud. Our best-in-class solutions help you address the toughest IT challenges, find new efficiencies and deliver the best application expe…

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now