Solved

Context Menu on CCheckBoxList Items only when an item is selected

Posted on 2010-11-18
5
451 Views
Last Modified: 2012-05-10
I have a Main UI (MP_UI),  which comprises of various controls. One of the controls is a ListBox Control.
The items inside are CCheckListBox based items.

What I am trying to do is add a context menu when the user selects  a check box item and right clicks. Right Click function should only be part of the listbox control (IDC_HOST_LIST)  and only when an item is selected.

I have a class CCheckListBoxMP, which is a derived class from CCheckListBox. The member functions in CCheckListBoxMP allows the user to do operations like add an item, delete an item, rename, update etc.

I added a WM_CONTEXTMENU to CCheckListBoxMP.cpp and implemented the function CCheckListBoxMP::OnContextMenu(CWnd, CPoint).

However I cannot seem to access the popup menu (which is partt of the MainUI.rc) in my CCheckListBoxMP. How will I do it.

Also how do I invoke right click on MainUI such that the OnContextMenu is correctly called and displayed.
0
Comment
Question by:mashey
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
5 Comments
 
LVL 19

Accepted Solution

by:
mrwad99 earned 125 total points
ID: 34172629
I can't see where the problem lies.  I tried the following code that displays a popup menu if the item right-clicked on is checked, and it works fine.  The menu IDR_MENU1 is loaded from my app's main resources without problem.

Can you elaborate on the issue you are having?

void CCheckListBoxMP::OnContextMenu(CWnd* pWnd, CPoint point)
{
      ScreenToClient ( &point );
      BOOL bInside = FALSE;
      UINT uItemSelected = ItemFromPoint ( point, bInside );
      if ( GetCheck ( uItemSelected ) != BST_CHECKED )
            return;

      CMenu menu;
      CMenu* pPopup;

      menu.LoadMenu(IDR_MENU1);
      pPopup = menu.GetSubMenu(0);
      ClientToScreen ( &point );
      pPopup->TrackPopupMenu( TPM_LEFTALIGN, point.x, point.y, this );

}
0
 
LVL 19

Expert Comment

by:mrwad99
ID: 34421915
The code I posted demonstrates how to achieve what the questioner is asking, so I believe I should have the points, please :)
0
 
LVL 53

Expert Comment

by:Dhaest
ID: 34505813
This question has been classified as abandoned and is being closed as part of the Cleanup Program.  See my comment at the end of the question for more details.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone 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

Title # Comments Views Activity
Re-position sub-options beneath the TAB 7 112
Beginner to Unreal Engine 4 5 119
Finding Divisors 5 60
Help with Progress 4gl Rounding Function 6 60
When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Navigation is an important part of web design from a usability perspective. But it is often a pain when it comes to a developer’s perspective. By navigation, it often means menuing. This is less theory and more practical of how to get a specific gro…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

734 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