Void CGlobalSFMMFCDlg: : OnSift ()
{
IsChecked=! IsChecked;
}
(2) the ON_UPDATE_COMMAND_UI message:
Void CGlobalSFMMFCDlg: : OnUpdateSift (CCmdUI * pCmdUI)
{
PCmdUI - & gt; SetCheck (isChecked);
}
(3) create your own OnInitMenuPopup:
Void CGlobalSFMMFCDlg: : OnInitMenuPopup (CMenu * pPopupMenu, UINT nIndex, BOOL bSysMenu)
{
//CDialogEx: : OnInitMenuPopup (pPopupMenu nIndex, bSysMenu);
ASSERT (pPopupMenu!=NULL);
CCmdUI state;
State. M_pMenu=pPopupMenu;
ASSERT (state. M_pOther==NULL);
ASSERT (state. M_pParentMenu==NULL);
HMENU hParentMenu;
If (AfxGetThreadState () - & gt; M_hTrackingMenu==pPopupMenu - & gt; M_hMenu)
State. M_pParentMenu=pPopupMenu;
Else if ((hParentMenu=: : GetMenu (m_hWnd))!=NULL)
{
The CWnd * pParent=this;
If (pParent!=NULL & amp; & (hParentMenu=: : GetMenu (pParent - & gt; M_hWnd))!=NULL)
{
Int nIndexMax=: : GetMenuItemCount (hParentMenu);
For (int nIndex=0; NIndex & lt; NIndexMax; NIndex++)
{
If (: : GetSubMenu (hParentMenu nIndex)==pPopupMenu - & gt; M_hMenu)
{
State. M_pParentMenu=CMenu: : FromHandle (hParentMenu);
break;
}
}
}
}
State. M_nIndexMax=pPopupMenu - & gt; GetMenuItemCount ();
For (state. M_nIndex=0; State. M_nIndex & lt; State. M_nIndexMax;
State. M_nIndex + +)
{
State. M_nID=pPopupMenu - & gt; GetMenuItemID (state. M_nIndex);
If (state. M_nID==0)
continue;
ASSERT (state. M_pOther==NULL);
ASSERT (state m_pMenu!=NULL);
If (state. M_nID==(UINT) - 1)
{
State. M_pSubMenu=pPopupMenu - & gt; GetSubMenu (state. M_nIndex);
If (state. M_pSubMenu==NULL | |
(state. M_nID=state. M_pSubMenu - & gt; GetMenuItemID (0))==0 | |
State. The m_nID==(UINT) - 1)
{
continue;
}
State. DoUpdate (this, TRUE);
}
The else
{
State. M_pSubMenu=NULL;
State. DoUpdate (this, FALSE);
}
UINT nCount=pPopupMenu - & gt; GetMenuItemCount ();
If (nCount & lt; State. M_nIndexMax)
{
State. M_nIndex -=(state. M_nIndexMax - nCount);
While (state. M_nIndex & lt; NCount & amp; &
PPopupMenu - & gt; GetMenuItemID (state. M_nIndex)==state. M_nID)
{
State. M_nIndex + +;
}
}
State. M_nIndexMax=nCount;
}
}
However, is not in front of the menu items checked??????? Urgent please
CodePudding user response:
Why nobody reply?CodePudding user response:
Because Internet has a lot of examplesCodePudding user response:
Overloaded function OnInitMenu, add the following code in the function:PMenu - & gt; CheckMenuItem (ID_ * * * * *, MF_BYCOMMAND | (isChecked? MF_CHECKED: MF_UNCHECKED));
The ID_ * * * * is a menu item ID, isChecked is your definition of a bool type variable,
Using this method doesn't need ON_UPDATE_COMMAND_UI message function, also do not need to override OnInitMenuPopup function,
CodePudding user response:
You should also can that method, you take//CDialogEx: : OnInitMenuPopup (pPopupMenu nIndex, bSysMenu); Try to remove this sentence annotations,CodePudding user response:
Dialog menu directly with CheckMenuItem