Click to See Complete Forum and Search --> : SetCheck(0)


July 12th, 1999, 11:27 AM
I was wondering how to set a checkmark by a menu item, and toggle between on/off each time the user clicked the menu item. I can do it with pop-up menus with EnableCheckItem( MF_CHECKED ), but with the dialog menu i can't do that?

thanks

dolittle
July 12th, 1999, 11:32 AM
Hi,

I had no such problem, I over written the virtual function for the MENU, (the ON_COMMAND, of the menu item), and did this inside that function:

GetMenu()->GetSubMenu(0)->CheckMenuItem(0, MF_CHECKED | MF_BYPOSITION );

This caused the first item to be marked as CHECKED (notice the GetSubMenu(0) and the MF_BYPOSITION (and of course the 0), you will need to adjust this acordingly).

Rail Jon Rogut
July 12th, 1999, 11:59 AM
In ClassWizard, select the menu item and add a function for the Message UPDATE_COMMAND_UI then add the code that's bold below:

void CYourDoc::OnUpdateMenuItem(CCmdUI* pCmdUI)
{
pCmdUI->SetCheck(m_bFlag);
}

Depending on if m_bFlag is TRUE or FALSE, the menu item will be checked... so in the function that's executed when you use this menu item:
void CYourDoc::OnMenuItem()
{
m_bFlag = !m_bFlag;

// Do something...
}

Rail

Recording Engineer/Software Developer
Rail Jon Rogut Software
railro@earthlink.net
http://home.earthlink.net/~railro/