Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

CListCtrl within a modeless dialog - mouse clicks

Posted on 1997-07-15
3
Medium Priority
?
480 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
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.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

670 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