보통 메뉴는 CMainFrame에 있습니다.
그래서 클래스 위져드에서 UPDATE_COMMAND_UI를 이용해서
만들어 주면은 아래와 같은 모양의 함수가 생성됩니다.

OnUpdateXXXXXXXX(CCmdUI* pCmdUI) { }

보통 위 합수에서
OnUpdateXXXXXXXX(CCmdUI* pCmdUI) { pCmdUI->Enable( TRUE ); // 활성화 pCmdUI->Enable( FALSE ); // 비활성화 }

해주면 메뉴의 항목이 활성/비활성 되는데

제가 이번에 만든건 특수하게 CTreeCtrl을 상속받아서 만든 객체에서 팝업메뉴를
만들었더니 'pCmdUI->Enable( FALSE );'를 아무리 해도 안되더라구요
CMenu::EnableMenuItem  함수를 사용해서 활성/비활성을 해줬습니다.
함수의 자세한 사용법은 아래에 ^^;

ps. EnableMenuItem() 함수는 TrackPopupMenu() 함수 전에 호출해 줘야 합니다.

CMenu::EnableMenuItem

UINT EnableMenuItem( UINT nIDEnableItem, UINT nEnable );

Return Value

Previous state (MF_DISABLED, MF_ENABLED, or MF_GRAYED) or –1 if not valid.

Parameters

nIDEnableItem

Specifies the menu item to be enabled, as determined by nEnable. This parameter can specify pop-up menu items as well as standard menu items.

nEnable

Specifies the action to take. It can be a combination of MF_DISABLED, MF_ENABLED, or MF_GRAYED, with MF_BYCOMMAND or MF_BYPOSITION. These values can be combined by using the bitwise OR operator. These values have the following meanings:

  • MF_BYCOMMAND   Specifies that the parameter gives the command ID of the existing menu item. This is the default.

  • MF_BYPOSITION   Specifies that the parameter gives the position of the existing menu item. The first item is at position 0.

  • MF_DISABLED   Disables the menu item so that it cannot be selected but does not dim it.

  • MF_ENABLED   Enables the menu item so that it can be selected and restores it from its dimmed state.

  • MF_GRAYED   Disables the menu item so that it cannot be selected and dims it.

Remarks

Enables, disables, or dims a menu item. The CreateMenu, InsertMenu, ModifyMenu, and LoadMenuIndirect member functions can also set the state (enabled, disabled, or dimmed) of a menu item.

Using the MF_BYPOSITION value requires an application to use the correct CMenu. If the CMenu of the menu bar is used, a top-level menu item (an item in the menu bar) is affected. To set the state of an item in a pop-up or nested pop-up menu by position, an application must specify the CMenu of the pop-up menu.

When an application specifies the MF_BYCOMMAND flag, Windows checks all pop-up menu items that are subordinate to the CMenu; therefore, unless duplicate menu items are present, using the CMenu of the menu bar is sufficient.


posted by 뚱2