Handling a right click message in a CListBox box control 
Author Message
 Handling a right click message in a CListBox box control
I have a situation where I have a single selection listbox control, and a
right click context menu. This is what currently happens - When I right
click anywhere in the listbox, the Context menu pops up, but the row focus
does not change (such as when the left mouse button is clicked). I have seen
many programs where a right mouse button is clicked, a context menu pops up,
AND the row focus changes to wherever the mouse was clicked in the list
box).

Currently, I am modifying some software where there is an owner draw list
box control directly derived from CListBox, and all listbox controls are
subclassed to this particular class. Anyway, I tried to create a new class,
derive it from the owner-draw list box, and add a new event handler which
simply calls the OnLButtonDown event in the CListBox control. This doesn't
work. I know that the event is working because if I stick a message box into
the event handler function, it pops up just fine (although, the context menu
doesn't if I have the message box in there).

Does anyone know how to handle this?

Thanks,
Chris Kokotaylo



Sat, 25 Oct 2003 01:56:34 GMT  
 Handling a right click message in a CListBox box control
Hello. First, you could put code in your CYourView::OnContextMenu(CWnd* pWnd,
CPoint point) handler, assuming that you handle this message already. From there
it gets shaky, as far as how I would handle what I think you want to do. Is it
possible to right click and get the context menu WITHOUT even being in the
listbox? If so, then you probably wouldn't want to shift the focus of whatever
the listbox is currently selecting in that case. Without knowing what your
screen looks like, you may or may not have to deal with determining whether the
right click occured in the listbox or not. Also, you assume that the user ALWAYS
wants to shift the focus (this is not intuitive to most users and could be
annoying), especially if the context menu can be used for commands that are not
specific to a selection. For example MS ACCESS does not shift the focus to the
cell where the context menu shows up, and I expressly avoided this as well,
because it can{*filter*}off people.

Anyway, I think the reason why your OLButtonDown call isn't working is because
the right click is going to your view class and not to your listbox, and the
message mapping won't route messages to you handler in the derived class.
CYourView::OnContextMenu should get called, and you might try calling your
lisbox's OnLButtonDown handler from that handler.

If that fails, then I would attempt to figure out a mapping between the point
that is passed to CYourView::OnContextMenu and the items in the listbox, and
programmatically change the selection.

Ed :)

Quote:

> I have a situation where I have a single selection listbox control, and a
> right click context menu. This is what currently happens - When I right
> click anywhere in the listbox, the Context menu pops up, but the row focus
> does not change (such as when the left mouse button is clicked). I have seen
> many programs where a right mouse button is clicked, a context menu pops up,
> AND the row focus changes to wherever the mouse was clicked in the list
> box).

> Currently, I am modifying some software where there is an owner draw list
> box control directly derived from CListBox, and all listbox controls are
> subclassed to this particular class. Anyway, I tried to create a new class,
> derive it from the owner-draw list box, and add a new event handler which
> simply calls the OnLButtonDown event in the CListBox control. This doesn't
> work. I know that the event is working because if I stick a message box into
> the event handler function, it pops up just fine (although, the context menu
> doesn't if I have the message box in there).

> Does anyone know how to handle this?

> Thanks,
> Chris Kokotaylo



Sat, 25 Oct 2003 03:53:27 GMT  
 Handling a right click message in a CListBox box control
It's really not hard to implement the described functionality yourself. You
mention you already have the subclass available, so I guess you have an
override for the OnRButtonDown message. Just use the CListBox::ItemFrom
point to get which item you are clicking over, and then do a SetCurSel to
move the selection to the new item.

Douglas Sutherland


Quote:
> I have a situation where I have a single selection listbox control, and a
> right click context menu. This is what currently happens - When I right
> click anywhere in the listbox, the Context menu pops up, but the row focus
> does not change (such as when the left mouse button is clicked). I have
seen
> many programs where a right mouse button is clicked, a context menu pops
up,
> AND the row focus changes to wherever the mouse was clicked in the list
> box).

> Currently, I am modifying some software where there is an owner draw list
> box control directly derived from CListBox, and all listbox controls are
> subclassed to this particular class. Anyway, I tried to create a new
class,
> derive it from the owner-draw list box, and add a new event handler which
> simply calls the OnLButtonDown event in the CListBox control. This doesn't
> work. I know that the event is working because if I stick a message box
into
> the event handler function, it pops up just fine (although, the context
menu
> doesn't if I have the message box in there).

> Does anyone know how to handle this?

> Thanks,
> Chris Kokotaylo



Sat, 25 Oct 2003 23:35:16 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Right-click on edit control or combo box...

2. Right-click in CListBox

3. problem Handling Click and double click messages in CListView

4. Right button mouse click in CListBox

5. (Q) Detecting right click in a CListBox

6. can clistbox respond to right click

7. problem Handling Click and double click messages in CListView

8. Handling a Right Click

9. Handling right click on static text??

10. how to capture right click messages on a button controll

11. List Box doesnt support Right Mouse Click --- Help needed

12. Right Mouse Click on List Box Not Supported

 

 
Powered by phpBB® Forum Software