Solved

Checking menu item in context menu

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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…
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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.
This is a video that shows how the OnPage alerts system integrates into ConnectWise, how a trigger is set, how a page is sent via the trigger, and how the SENT, DELIVERED, READ & REPLIED receipts get entered into the internal tab of the ConnectWise …

948 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

22 Experts available now in Live!

Get 1:1 Help Now