Solved

CListCtrl within a modeless dialog - mouse clicks

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

Get MySQL database support online, now!

At Percona’s web store you can order your MySQL database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card.

Question has a verified solution.

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

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
In this post we will learn different types of Android Layout and some basics of an Android App.
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.
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

636 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