Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Detecting CListBox (Mouse) events

Posted on 2001-07-19
5
Medium Priority
?
456 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:Meir Rivkin
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:
Meir Rivkin earned 200 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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
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.
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …

916 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