Solved

Detecting CListBox (Mouse) events

Posted on 2001-07-19
5
438 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
Comment Utility
goto your CListBox derived class and remove the message handler OnDblClk from protected to the public. thats all.
0
 

Author Comment

by:FlipFlop
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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.
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.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

762 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

15 Experts available now in Live!

Get 1:1 Help Now