Right click on a list box

This is a discussion on Right click on a list box within the Windows Programming forums, part of the Platform Specific Boards category; Anyone know how to intercept this in a list box control? I've already had to implement some custom message handling ...

  1. #1
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,598

    Right click on a list box

    Anyone know how to intercept this in a list box control? I've already had to implement some custom message handling because MFC doesn't quite do the job well enough.

    I've tried just about everything, yet the right click is swallowed by the list control even though I don't know how to respond to it.
    RButtonDown only goes to the window when the cursor is not over the list control.

    So it does the exact opposite of what I want. A tree control intercepts a right click just fine. There has to be a way to do it, or emulate it.

  2. #2
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,265
    The parent window will receive a WM_CONTEXTMENU message. The wParam of this message will be the HWND of your list control when the user right clicks on it.

  3. #3
    Registered User
    Join Date
    Mar 2005
    Location
    Juneda
    Posts
    287
    maybe you can work with the WM_NOTIFY messages. from them you can filter those who cames from the control you want to work with (switching the LOWORD((LPARAM)yourlparam) till get the identifyer, the same as when you work with the WM_COMMAND messages). then using the LPARAM filter the events and get only the NM_RCLICK, with something like
    Code:
    case WM_NOTIFY:
            {
            switch(LOWORD(wParam))
                {
                case ID_OF_YOUR_CONTROL:
                    {
                    switch(((LPNMHDR)lParam)->code)
                        {
                        case NM_RCLICK:
                            {
                             //well, we're here
                            }
                        break;
    //remember to close all brakets :)
    if you use also a WM_CONTEXTMENU it will 'run' before that code (I think, I'm not testing it now), so it will be a good idea to test from the contextmenu function to test if the rclick has done over a control, or better on the notify msg verify if the click is valid from the control you want to get it's rclick (or for all the controls that you want to verify it), if no then force a contextmenu message.
    an observation, that doesn't need to be mfc
    niara

  4. #4
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,598
    bithub your suggestion works perfect. Thanks a million.

    Code:
    CRect rect;
      m_lstLayers.GetWindowRect(&rect);
    
      if (PtInRect(&rect,point))
      {
        CMenu *temp=RMenu->GetSubMenu(0);
        temp->TrackPopupMenu(TPM_LEFTALIGN | TPM_TOPALIGN,point.x,point.y,this);
      }
    I can't use the CWnd pointer because that would infer that all my child windows have right click menus and they don't. So I use this as a handler for all the different windows that do have right click menus. It works like a charm. I'm adding code to the CPropertyPage class to support greyed out popup menu items. When I get this done, I'll use that as the base class for my property pages instead of CPropertyPage.

    Thanks a million.

    Here is an update screenshot. You'll notice that I've de-cluttered the desktop by sticking most of the windows in a CPropertySheet.
    Last edited by VirtualAce; 01-05-2006 at 08:21 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. fgets() to list box
    By tao in forum Windows Programming
    Replies: 4
    Last Post: 06-08-2006, 09:23 AM
  2. Dialog Box Problems
    By Morgul in forum Windows Programming
    Replies: 21
    Last Post: 05-31-2005, 06:48 PM
  3. problem with structures and linked list
    By Gkitty in forum C Programming
    Replies: 6
    Last Post: 12-12-2002, 06:40 PM
  4. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 10:44 AM
  5. List class
    By SilasP in forum C++ Programming
    Replies: 0
    Last Post: 02-10-2002, 05:20 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21