Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Context Menu on CCheckBoxList Items only when an item is selected

Posted on 2010-11-18
5
Medium Priority
?
462 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 500 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Article by: evilrix
Looking for a way to avoid searching through large data sets for data that doesn't exist? A Bloom Filter might be what you need. This data structure is a probabilistic filter that allows you to avoid unnecessary searches when you know the data defin…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
Suggested Courses

916 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