Solved

Context Menu on CCheckBoxList Items only when an item is selected

Posted on 2010-11-18
5
450 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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
This article will show, step by step, how to integrate R code into a R Sweave document
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

756 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