Solved

Context Menu on CCheckBoxList Items only when an item is selected

Posted on 2010-11-18
5
442 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
  • 2
5 Comments
 
LVL 19

Accepted Solution

by:
mrwad99 earned 125 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now