Solved

Checking menu item in context menu

Posted on 1998-08-13
3
203 Views
Last Modified: 2013-11-20
Hi guys,

in my program I create a context menu containing two sub menus. When I select a menu item from one of the sub menus I want it to be checked. So I used the OnUpdate... function to check the item with  pCmdUI->SetCheck(1);  When debugging the program the function is called, the ID is correct and everything seems to be fine. But when I want to select the item again, it isn´t checked. Can somebody help me ??

Thanks in advance

Nick
0
Comment
Question by:nl1545
[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
3 Comments
 

Expert Comment

by:t004024
ID: 1320724
When handling the WM_CONTEXTMENU how are U displaying the context menu? If U are loading/creating the menu everytime, then U have to do the explicitly setting of check depending on whether U had it previously selected or not.

0
 
LVL 8

Accepted Solution

by:
Answers2000 earned 50 total points
ID: 1320725
I suspect you are reloading the menu from the resource file each time ?

EITHER
Save the state in a variable (e.g. add a boolean to the class), and then whenever you setup the menu, set the initial checked/unchecked state depending on the value in this variable.

OR
Load the menu once (e.g. in your constructor) and simply redisplay it each time.

Personally I prefer the first solution, as you can write one function ("PrepareMenu") and keep all the menu state logic in once place.  This is useful if you later add more check options, default options or radio options to the menu.

0
 

Author Comment

by:nl1545
ID: 1320726
Thank you,

I thought the COMMAND_UPDATE_UI handler would be called BEFORE the menu is displayed for the first time (as it is with normal items)
But your hint does solve my problem, too

Nick
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

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …

626 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