Solved

Context Menu on CCheckBoxList Items only when an item is selected

Posted on 2010-11-18
5
448 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
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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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
Programatically extract date from website 8 79
Problem to open text file 11 128
Bartender Integration Builder 3 44
Where are the c++ header files to use in Eclipse? 4 24
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
If you haven’t already, I encourage you to read the first article (http://www.experts-exchange.com/articles/18680/An-Introduction-to-R-Programming-and-R-Studio.html) in my series to gain a basic foundation of R and R Studio.  You will also find the …
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
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.

837 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