From: Zapanaz on


I have a class derived from CListCtrl, which I've named DbListCtrl.

I have an instance of it in a dialog, created in the MFC
class/interface designer interface. This allows me to use the Class
Wizard on it, but, I also need to be able to create instances
dynamically. That is, I have a DbListCtrl in a dialog, but the user
can also open ones in separate windows.

So far, this works fine.

So I need to know if the user clicks in the DbListCtrl, and also if
the user double-clicks.

So I use the class wizard. In Message Maps, under Object IDs, I can
select the ID of the DbListCtrl, or the class. That is in the list it
shows me IDC_DB_LIST, the ID of the object in the dialog, or
DbListCtrl, the name of the class.

If I select the ID and then message NM_CLICK, it's a problem, because
the message map entry it creates includes the ID IDC_DB_LIST. But I
also want to be notified if I create new instances of DbListCtrl, so
that isn't going to work.

So instead I select DbListCtrl, select =NM_CLICK from the message map
choices, and add a function for that.

That works fine. When I single click either in the class in the
dialog, or in a new instance in a separate window, it executes my
code.

But I also need to know if it has been double-clicked. So I take the
same approach, select DbListCtrl in the class wizard, and =NM_DBLCLK,
and it adds a function for that.

If I double-click the DbListCtrl in the dialog, it works, but if I
open it in a new window (a new instance of the class) and double
click, it doesn't.

The message map entries are like this

BEGIN_MESSAGE_MAP(DbListCtrl, CListCtrl)
//{{AFX_MSG_MAP(DbListCtrl)
ON_NOTIFY_REFLECT(NM_CLICK, OnClick)
ON_NOTIFY_REFLECT(NM_DBLCLK, OnDblclk)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

I mean they seem identical. Maybe it's in the logic of
"NOTIFY_REFLECT", I really don't completely understand what that even
means, what exactly the difference between that form of notification
is and the other macro which was created when I used the class ID in
the class wizard.

But I don't really see a way around using that approach if I don't
want the notifications to only apply to one instance of my class.

Does anybody know why the double click message isn't working for
instances of my class other than the one I created in the class
wizard?

Or if there is a different way I could, or should, be setting up the
message map such that I can use it for all instances of my class,
rather than the one I create in the class wizard?

Thanks for any help.




--
Joe Cosby
http://joecosby.com/
"Art is a house that tries to be haunted."
--Emily Dickinson

:: Currently listening to Look For the Sunset, 2006, by Samite, from "Embalasasa"