title: MFC - Check/Uncheck menu item
body: <p>I have an MFC application I'm making, in which there are two menu options corresponding to two toolbars - the menu options toggle visibility of the tool bars.  I need the menu options to be checked if the tool bar is currently visible.  Here's what I've got so far:</p>
  
  <pre><code>BEGIN_MESSAGE_MAP(CLevelPackEditApp, CWinAppEx)
      // Standard file based document commands
      ON_UPDATE_COMMAND_UI(ID_LEVEL_PROPERTIES, &amp;CLevelPackEditApp::OnViewLevelProperties)
  END_MESSAGE_MAP()
  
  void CLevelPackEditApp::OnViewLevelProperties(CCmdUI* pCmdUI)
  {
      // Get a handle to the main window
      CMainFrame* main = ((CMainFrame*)m_pMainWnd);
  
      // Get a handle to the level properties toolbar for the main window
      CLevelProperties* obj = main-&gt;GetLevelProperties();
  
      if (obj-&gt;IsWindowVisible())
      {
          pCmdUI-&gt;SetCheck(0);
          obj-&gt;ShowPane(false, false, false);
      } else {
          pCmdUI-&gt;SetCheck();
          obj-&gt;ShowPane(true, false, true);
      }
  }
  </code></pre>
  
  <p>It works....sort of.  It toggles between checked and not checked, but it does so multiple times per second - I suspect that checking the menu item causes the menu to update, so it is unchecked, so it updates, so it is checked, aaaannnd repeat.  How can I get around this?</p>