VS6.0文档视图框架程序中CHECKED选项代码操作小结

第一步:在菜单的关联函数中,判断是否选中及相关处理

void CDCMS3000MainView::OnMenuAutoRun()

{

     // TODO: Add your command handler code here

      if( AfxGetMainWnd()->GetMenu()->GetMenuState(ID_MENU_AUTORUN, MF_BYCOMMAND)

           == MF_UNCHECKED )

      {

            SBF_OnRegItemAR( ((CDCMS3000MainApp*)AfxGetApp())->m_strLocalEXEPathName,

                 "PDT3000.DCMS3000Main");

     

            ((CDCMS3000MainApp*)(AfxGetApp()))->m_nRunMode = 1;

            ::WritePrivateProfileString("DCMS3000", "AUTORUN", "1",

                 ((CDCMS3000MainApp*)AfxGetApp())->m_strLocalINIPathName);

            AfxGetMainWnd()->GetMenu()->CheckMenuItem(ID_MENU_AUTORUN, MF_CHECKED);

      }

      else

      {

            SBF_OffRegItemAR();

     

            ((CDCMS3000MainApp*)(AfxGetApp()))->m_nRunMode = 0;

            ::WritePrivateProfileString("DCMS3000", "AUTORUN", "0",

                 ((CDCMS3000MainApp*)AfxGetApp())->m_strLocalINIPathName);          

            AfxGetMainWnd()->GetMenu()->CheckMenuItem(ID_MENU_AUTORUN, MF_UNCHECKED);

      }

}

注:SBF_ 开头的外部库文件主要用来实现,注册自动运行注册表项,此处做了简单封装

第二步:在菜单的 UPDATE_COMMAND_UI 消息中,添加实时选中处理

void CDCMS3000MainView::OnUpdateMenuAutoRun(CCmdUI* pCmdUI)

{

     // TODO: Add your command update UI handler code here

      if( ((CDCMS3000MainApp*)(AfxGetApp()))->m_nRunMode == 1 )

      {

            pCmdUI->SetCheck(true);

      }

      else

      {

            pCmdUI->SetCheck(false);

      }

}

注:m_nRunMode 可从配置文件或注册表项中获取程序运行模式,改变程序内存变量,从而影响菜单特征项

 

你可能感兴趣的:(VS6.0文档视图框架程序中CHECKED选项代码操作小结)