¸Þ´º ´ëÈ »óÀÚ°¡ ¿¬°áµÇ¾î ÀÖÀ¸¸é ÇØ´ç ¸í·É (UI (»ç¿ëÀÚ ÀÎÅÍÆäÀ̽º 󸮱Ⱑ ¸Þ´º Ç׸ñÀÇ »óÅ (»ç¿ë/»ç¿ë ¾È ÇÔ, È®ÀÎ/È®ÀÎ Ãë¼Ò¸¦, º¯°æ ÅØ½ºÆ®) º¯°æÇÏ´Â ±â´ÉÀÌ Á¦´ë·Î ÀÛµ¿ÇÏÁö ¾Ê½À´Ï´Ù:
void CTestDlg::OnUpdateFileExit(CCmdUI* pCmdUI)
{
pCmdUI->Enable(FALSE); //Not calling the command handler, but does not show as disabled.
pCmdUI->SetCheck(TRUE); // Does not show check mark before the text.
pCmdUI->SetRadio(TRUE); // Does not show dot before the text.
pCmdUI->SetText("Close"); //Does not change the text.
}
µå·Ó´Ù¿î ¸Þ´º°¡ Ç¥½ÃµÉ ¶§ ÇØ´ç WM_INITMENUPOPUP ¸Þ´º Ç׸ñÀ» Ç¥½ÃÇϱâ Àü¿¡ ¸Þ½ÃÁö°¡ º¸³»Áý´Ï´Ù. MFC
CFrameWnd::OnInitMenuPopup ÇÔ¼ö¸¦ ÅëÇØ ¸Þ´º Ç׸ñÀ» ¹Ýº¹ÇÏ°í °æ¿ì Ç׸ñ¿¡ ´ëÇÑ ¾÷µ¥ÀÌÆ® ¸í·É UI 󸮱⸦ È£ÃâÇÕ´Ï´Ù. °¢ ¸Þ´º Ç׸ñÀÇ ¸ð¾çÀº (»ç¿ë/»ç¿ë ¾ÈÇÔ, üũ/unchecked) ±× »óŸ¦ ¹Ý¿µÇϵµ·Ï ¾÷µ¥ÀÌÆ®µË´Ï´Ù.
¾÷µ¥ÀÌÆ® UI ¸ÞÄ¿´ÏÁòÀÌ ÀÖ´Â ´ëÈ »óÀÚ ±â¹Ý ÀÀ¿ë ÇÁ·Î±×·¥À» À§ÇÑ
CDialogOnInitMenuPopup 󸮱Ⱑ ÀÖÀ¸¹Ç·Î ¸í·É ¾÷µ¥ÀÌÆ® UI 󸮱⠸޴º Ç׸ñ¿¡ ´ëÇØ È£ÃâÇÒ
CWnd ÀÇ ±âº» 󸮱⸦ »ç¿ëÇÏ´Â ÀÛµ¿ÇÏÁö ¾Ê½À´Ï´Ù.
ÀÌ ¹®Á¦¸¦ ÇØ°áÇÏ·Á¸é ´ÙÀ½°ú °°ÀÌ ÇϽʽÿÀ.
- ¸Þ½ÃÁö ¸Ê¿¡ ON_WM_INITMENUPOPUP Ç׸ñÀ» Ãß°¡ÇÏ·Á¸é:
BEGIN_MESSAGE_MAP(CTestDlg, CDialog)
//}}AFX_MSG_MAP
ON_WM_INITMENUPOPUP()
END_MESSAGE_MAP()
- ´ëÈ »óÀÚ Å¬·¡½º¿¡ OnInitMenuPopup ¸â¹ö ÇÔ¼ö¸¦ Ãß°¡ÇÏ°í ´ÙÀ½ Äڵ带 (ÀÌ ÄÚµå´Â ´ëºÎºÐ CFrameWnd::OnInitMenuPopup WinFrm.cpp¿¡¼ °¡Á®¿Â °ÍÀÔ´Ï´Ù Âü°í) º¹»ç:
void CTestDlg::OnInitMenuPopup(CMenu *pPopupMenu, UINT nIndex,BOOL bSysMenu)
{
ASSERT(pPopupMenu != NULL);
// Check the enabled state of various menu items.
CCmdUI state;
state.m_pMenu = pPopupMenu;
ASSERT(state.m_pOther == NULL);
ASSERT(state.m_pParentMenu == NULL);
// Determine if menu is popup in top-level menu and set m_pOther to
// it if so (m_pParentMenu == NULL indicates that it is secondary popup).
HMENU hParentMenu;
if (AfxGetThreadState()->m_hTrackingMenu == pPopupMenu->m_hMenu)
state.m_pParentMenu = pPopupMenu; // Parent == child for tracking popup.
else if ((hParentMenu = ::GetMenu(m_hWnd)) != NULL)
{
CWnd* pParent = this;
// Child windows don't have menus--need to go to the top!
if (pParent != NULL &&
(hParentMenu = ::GetMenu(pParent->m_hWnd)) != NULL)
{
int nIndexMax = ::GetMenuItemCount(hParentMenu);
for (int nIndex = 0; nIndex < nIndexMax; nIndex++)
{
if (::GetSubMenu(hParentMenu, nIndex) == pPopupMenu->m_hMenu)
{
// When popup is found, m_pParentMenu is containing menu.
state.m_pParentMenu = CMenu::FromHandle(hParentMenu);
break;
}
}
}
}
state.m_nIndexMax = pPopupMenu->GetMenuItemCount();
for (state.m_nIndex = 0; state.m_nIndex < state.m_nIndexMax;
state.m_nIndex++)
{
state.m_nID = pPopupMenu->GetMenuItemID(state.m_nIndex);
if (state.m_nID == 0)
continue; // Menu separator or invalid cmd - ignore it.
ASSERT(state.m_pOther == NULL);
ASSERT(state.m_pMenu != NULL);
if (state.m_nID == (UINT)-1)
{
// Possibly a popup menu, route to first item of that popup.
state.m_pSubMenu = pPopupMenu->GetSubMenu(state.m_nIndex);
if (state.m_pSubMenu == NULL ||
(state.m_nID = state.m_pSubMenu->GetMenuItemID(0)) == 0 ||
state.m_nID == (UINT)-1)
{
continue; // First item of popup can't be routed to.
}
state.DoUpdate(this, TRUE); // Popups are never auto disabled.
}
else
{
// Normal menu item.
// Auto enable/disable if frame window has m_bAutoMenuEnable
// set and command is _not_ a system command.
state.m_pSubMenu = NULL;
state.DoUpdate(this, FALSE);
}
// Adjust for menu deletions and additions.
UINT nCount = pPopupMenu->GetMenuItemCount();
if (nCount < state.m_nIndexMax)
{
state.m_nIndex -= (state.m_nIndexMax - nCount);
while (state.m_nIndex < nCount &&
pPopupMenu->GetMenuItemID(state.m_nIndex) == state.m_nID)
{
state.m_nIndex++;
}
}
state.m_nIndexMax = nCount;
}
}
À̰ÍÀº ÀǵµÀûÀ¸·Î ¼³°èµÈ µ¿ÀÛÀÔ´Ï´Ù.
¶ÇÇÑ ¸í·É ¾÷µ¥ÀÌÆ® UI 󸮱â ÀÖ´ÂÁö ¸í·ÉÀ» ¶ó¿ìÆÃÇϱâ Àü¿¡ »ç¿ëÇÒ µÉ ¼ö ¾øÀ½À» ¾ÊÀº
CWnd::OnCommand È£ÃâµË´Ï´Ù. ȸ»öÀ¸·Î ³ªÅ¸³³´Ï´Ù °æ¿ì¿¡µµ ¸í·É 󸮱⸦ »ç¿ëÇÒ ¼ö ¾ø´Â ¸Þ´º Ç׸ñ¿¡ ´ëÇÑ (»ç¿ëÇÒ ¼ö ¾øÀ½) È£ÃâµÇÁö ¾ÊÀº ÀÌÀ¯°¡ ¹Ù·Î À̰ÍÀÔ´Ï´Ù. ÀÌ °æ¿ì ÇØ´ç »óŸ¦ ¹Ý¿µÇϵµ·Ï ¸Þ´º Ç׸ñÀº ±×¸®´ÂÁö ¾Ê½À´Ï´Ù. Wincore.cpp ÆÄÀÏ¿¡¼ °ü·Ã ÄÚµåÀÔ´Ï´Ù:
// Make sure command has not become disabled before routing.
CTestCmdUI state;
state.m_nID = nID;
OnCmdMsg(nID, CN_UPDATE_COMMAND_UI, &state, NULL);
if (!state.m_bEnabled)
{
TRACE1("Warning: not executing disabled command %d\n", nID);
return TRUE;
}
Windows Mobile ±â¹Ý ½º¸¶Æ®Æù¿¡ GPRS ¿¬°áÀÌ ±¸¼ºµÇ¾î ÀÖ´ÂÁö È®ÀÎÇÕ´Ï´Ù
Visual C++ .NETÀÇ ÀÌ ¹®Á¦¸¦ ÀçÇöÇÏ·Á¸é ´ÙÀ½°ú °°ÀÌ ÇϽʽÿÀ.
- ÀÀ¿ë ÇÁ·Î±×·¥ ¸¶¹ý»ç ´ëÈ »óÀÚ ±â¹Ý MFC ÀÀ¿ë ÇÁ·Î±×·¥À» ¸¸µì´Ï´Ù.
- »õ ¸Þ´º ¸®¼Ò½º¸¦ ¸¸µé°í ÆÄÀÏ ¹× ÆÄÀÏ/³¡³»±â ¸Þ´º Ç׸ñÀ» Ãß°¡ÇϽʽÿÀ.
- ÀÌ ¸Þ´º ´ëÈ »óÀÚ´Â ¼Ó¼º â¿¡¼ ´ëÈ »óÀÚ¿¡ ´ëÇÑ ¸Þ´º¸¦ ¼³Á¤ÇϽʽÿÀ. ÀÌ·¸°Ô ÇÏ·Á¸é ´ëÈ »óÀÚ ÆíÁý±â¿¡¼ ´ëÈ »óÀÚ ¸®¼Ò½º¸¦ ¿±´Ï´Ù. ¼Ó¼º â¿¡¼ ¸Þ´º Ŭ¸¯ÇÏ¿©°¡ ¼±ÅÃÇÕ´Ï´Ù. »õ ¸Þ´º ¸®¼Ò½º ID ¸Þ´º ¼Ó¼º ÆíÁý±â µå·Ó´Ù¿î ¸ñ·Ï¿¡ Ç¥½ÃµË´Ï´Ù.
- ÆÄÀÏ/³¡³»±â ¸Þ´º Ç׸ñ¿¡ ´ëÇÑ UPDATE_COMMAND_UI 󸮱⸦ Ãß°¡ÇϽʽÿÀ. ÀÌ·¸°Ô ÆÄÀÏ/³¡³»±â ¸Þ´º ÆíÁý±â¿¡¼ ¸¶¿ì½º ¿À¸¥ÂÊ ´ÜÃ߷ΠŬ¸¯ÇÑ ´ÙÀ½ À̺¥Æ® 󸮱â Ãß°¡ ¼ö ÀÖ½À´Ï´Ù. À̺¥Æ® 󸮱⠸¶¹ý»ç¿¡¼ UPDATE_COMMAND_UI 󸮱⸦ CDialog ÆÄ»ý Ŭ·¡½º¸¦ ÇÁ·ÎÁ§Æ®¿¡ Ãß°¡ÇϽʽÿÀ. ÇØ´ç 󸮱⸦ ¸¸µé·Á¸é Ãß°¡ ¹× ÆíÁý Ŭ¸¯ÇÑ ´ÙÀ½ ÀÌ·¯ÇÑ ¹® Áß Çϳª°¡ »ý¼ºµÈ 󸮱⠸޼µå¸¦ Ãß°¡ÇÒ:
pCmdUI->Enable(FALSE); //Not calling the handler, but does not show as disabled
pCmdUI->SetCheck(TRUE); // Does not show check mark before the text.
pCmdUI->SetRadio(TRUE); // Does not show dot before the text.
pCmdUI->SetText("Close"); //Does not change the text.
- ºôµå ¹× ÀÀ¿ë ÇÁ·Î±×·¥À» ½ÇÇàÇϽʽÿÀ.
Ãß°¡ Á¤º¸´Â ´ÙÀ½ ¹®¼ ¹øÈ£¸¦ Ŭ¸¯ÇÏ¿© Microsoft ±â¼ú ÀÚ·á¿¡¼ È®ÀÎÇϽʽÿÀ:
141751?
(http://support.microsoft.com/kb/141751/
)
MFC ´ëÈ »óÀÚ¿¡ ÄÁÆ®·Ñ ¸·´ë Ãß°¡