Solved

Checking menu item in context menu

Posted on 1998-08-13
3
196 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
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Installing Microsoft R server on REDHAT or SUSE Linux 4 125
modThree challenge 4 64
Fibonacci challenge 11 82
Problem to event 3 50
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

705 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

17 Experts available now in Live!

Get 1:1 Help Now