Solved

Detecting CListBox (Mouse) events

Posted on 2001-07-19
5
444 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
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.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

808 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