Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

check/uncheck a menu item

Posted on 2001-06-30
2
Medium Priority
?
566 Views
Last Modified: 2013-11-20
I am using Visual C++ 6.0
I have made a "hello world" program via the wizard
I have added a menu item to the window
with the name ID_CONNECTIONS

My question is

I want, when the user select the menu item, check and uncheck the menu item with the name ID_CONNECTIONS.

What source code should I add to the project created by
the wizard so this happends.



0
Comment
Question by:kung
2 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 6241164
You can achieve that using 'CMenu::CheckMenuItem()'

You'll have to obtain the meu handle for your window first:

CMenu *pmenu = AfxGetMainWnd()->GetMenu();

pmenu->CheckMenuItem ( ID_CONNECTIONS, MF_BYCOMMAND | MF_CHECKED); // to check the item

pmenu->CheckMenuItem ( ID_CONNECTIONS, MF_BYCOMMAND | MF_UNCHECKED); // to uncheck the item


0
 
LVL 12

Accepted Solution

by:
migel earned 900 total points
ID: 6241170
Hi!
1. open wizard dialog (Ctrl+W)
2. select your frame class in the second combobox.
 select in the left list ID_CONNECTIONS.
Double click in the right list on the UPDATE_COMMAND_UI item
3.Press OK in the appeared dialog.
4. double click on the added item in the bottom list.
5. In the editor window:
void CMainFrame::OnConnectionsUpdate(CCmdUI* pCmdUI)
{
    pCmdUI->SetCheck(bCheck); // this code sets or remove check in the menu depending on bCheck value
}


0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

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…
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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.
Integration Management Part 2
Suggested Courses

886 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