Solved

Detecting CListBox (Mouse) events

Posted on 2001-07-19
5
441 Views
Last Modified: 2013-11-20
Hi,

I have a CListbox on a property page, which I converted
to a draglistbox by overriding the member variable so
that its a CDragListBox type. When you double click on
an item in the listbox a dialog box appears, different
one each time depending on the item selected. I called
the listbox class CMyListBox.

Then to use the CDragListBox member functions, e.g.,
Dropped() I subclassed CMyListBox to CDragList. I then
added in the Dropped() function in CDragList, which
works fine. But now when I double click on an entry in
my listbox it goes straight into the Dropped() function
and the dialog box associated with the entry in the
listbox doesn't appear. I assume this is because when
you double click on an item in the listbox, after
the first click is detected it goes into Dropped(), so
the second click is never registered and OnDblClk() in
CMyListBox is never called.

How can I make my application distinguish between a
single click (when perform drag and drop) and a double
click when wanting to display the associated dialog box.

I tried to put in a call in the Dropped() function in
my subclass to OnDblClk() in CMyListBox? like  

void CDragList::Dropped()
{
  // Do some stuff

  CMyListBox::OnDblClk();
}


but it failed, said that I couldn't call a protected
member function. Whats the right way to do this?


FlipFlop


0
Comment
Question by:FlipFlop
  • 3
  • 2
5 Comments
 
LVL 42

Expert Comment

by:sedgwick
ID: 6297394
goto your CListBox derived class and remove the message handler OnDblClk from protected to the public. thats all.
0
 

Author Comment

by:FlipFlop
ID: 6297510
Hi,

I've tried that before and it didn't work.  Maybe I'm not
doing it right.  Heres what I tried, in file CMyListBox.h

######################################################
class CMyListBox : public CPropertyPage
{
     DECLARE_DYNCREATE(CMyListBox)
private:

// Construction
public:
     CMyListBox ();
     ~CMyListBox ();

// Dialog Data
     //{{AFX_DATA(CMyListBox )
     enum { IDD = IDD_MYLIST };
     CDragList     m_pMyList;
     //}}AFX_DATA


// Overrides
     // ClassWizard generate virtual function overrides
     //{{AFX_VIRTUAL(CMyListBox )
     public:
     void OnDblclk();
     protected:
     virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
     //}}AFX_VIRTUAL

// Implementation
protected:
     // Generated message map functions
     //{{AFX_MSG(CMyListBox)
     virtual BOOL OnInitDialog();
     //}}AFX_MSG
     DECLARE_MESSAGE_MAP()

};
######################################################

When I compile I get the same error message.

DragList.cpp(64) : error C2352: 'CMyListBox::OnDblclk' : illegal call of non-static member function



Confused, FlipFlop

0
 
LVL 42

Accepted Solution

by:
sedgwick earned 50 total points
ID: 6297904
to call your OnDblClick of the CMyListBox u should use your instance, the way u used here is to call static functions.

CMyListBox listbox;
listbox.OnDblclk();

now its gonna work.

0
 

Author Comment

by:FlipFlop
ID: 6299169
Hi Sedgwick,

Yep its working!  Thanks for that.  I've accepted your
answer but as an end note I wonder if you could explain
it.  When you do a

CMyListBox listbox;

I would have expected another listbox to be instantiated,
how is it that it controls my existing listbox?

Cheers, FlipFlop
0
 

Author Comment

by:FlipFlop
ID: 6299177
Hi Sedgwick,

Yep its working!  Thanks for that.  I've accepted your
answer but as an end note I wonder if you could explain
it.  When you do a

CMyListBox listbox;

I would have expected another listbox to be instantiated,
how is it that it controls my existing listbox?

Cheers, FlipFlop
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
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.
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

863 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now