Solved

CListCtrl within a modeless dialog - mouse clicks

Posted on 1997-07-15
3
454 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 100 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
WinWaitActive parameters 12 31
sameEnds challenge 3 196
zeroMAx challenge 20 135
x-bar in Google Sheets 2 129
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
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.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

739 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