Solved

Checking menu item in context menu

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

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…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

679 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