Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

CListCtrl within a modeless dialog - mouse clicks

Posted on 1997-07-15
3
Medium Priority
?
490 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 200 total points
ID: 1302581
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
ID: 1302582
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
ID: 1302583
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

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

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

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

772 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