Solved

CListCtrl within a modeless dialog - mouse clicks

Posted on 1997-07-15
3
397 Views
Last Modified: 2013-11-20
I have added a CListCtrl to a modeless dialog box and am having trouble processing a left double click or a right single click on elements in the list. Since the list control has its own window the message handlers on the dialog do not get called for clicks within the list control. How do I get these message and how do I figure out where the click occurred? Is it on an item? What is the item?
0
Comment
Question by:rhans042197
3 Comments
 
LVL 4

Accepted Solution

by:
mbhakta earned 100 total points
Comment Utility
Yes, that is right. The message of the list control have to be handled by the list control himself. To get more messages to work on the list control . Derive a class say CMyListCtrl from CListCtrl. Now override all the list control messages you want to work on. For instance HitTest() is one such overridable function you will need to work on for determining where the user clicked. This is one of the best way to trap message processing in MFC. The derived class can then be used in your source file either as an replacement to CListCtrl or also can be used to SubclassDlgItem().
0
 

Author Comment

by:rhans042197
Comment Utility
Thanks for the response but what I have done is created a derived class from the CListCtrl called CMyListCtrl. I then have an instance variable in my modeless dialog called:

     CMyListCtrl   MyListCtrl;

In the OnInitDialog() method, I do the following:

     MyListCtrl.SubclassDlgItem(CFINDDIALOG_LIST, this);

I then have virtual declarations of the messages that I am interested in:

    class CMyListCtrl::public CListCtrl
    {
      virtual void OnLButtonDblClk(UINT nFlags, CPoint point);
      virtual void OnRButtonDown(UINT nFlags, CPoint point);
    };

When I left double click or single right click, my virtuals DO NOT get called. Is there something that I am missing?

Raj
(rhans@magi.com)
0
 
LVL 10

Expert Comment

by:RONSLOW
Comment Utility
Thats not how you do it.  These "virtuals" don't exist in the base class so they won't get called.  Also they are not the events you really want to process.

You need to write handlers like..

ON_NOTIFY_REFLECT(NM_DBLCLK, OnDblclk)
ON_NOTIFY_REFLECT(NM_RCLICK, OnRclick)
ON_NOTIFY_REFLECT(NM_CLICK, OnClick)

...to handle these.  Notice that you must use the _REFLECT versions so the control can handle the messages instead of the dialog in which you place it.

The handler routines look like..

void CMyListCtrl::OnClick(NMHDR* pNMHDR, LRESULT* pResult) {
    // look at pNMHDR to get info about where the click was
}

Roger

PS: Why do you use SubclassDlgItem instead of using MFC DDX_CONTROL which does all the necessary work for you?

0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Decoding 32 bit binary streams 6 30
configuration management 2 99
Error on moodle after upgrade 3 105
Expand data scrubbing tool 13 29
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

771 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

9 Experts available now in Live!

Get 1:1 Help Now