Share via


CMenu::SetMenuItemBitmaps

會將指定的點陣圖與功能表項目產生關聯。

BOOL SetMenuItemBitmaps(
   UINT nPosition,
   UINT nFlags,
   const CBitmap* pBmpUnchecked,
   const CBitmap* pBmpChecked 
);

參數

  • nPosition
    指定要變更的功能表項目。 nFlags 參數可用來透過下列方式說明 nPosition :

    nFlags

    nPosition 的說明

    MF_BYCOMMAND

    指定參數指定現有的功能表項目的命令 ID。 如果 MF_BYCOMMANDMF_BYPOSITION 未設定,這是預設值。

    MF_BYPOSITION

    指定參數重新命名現有的功能表項目的位置。 第一個項目在位置 0。

  • nFlags
    指定 nPosition 如何解譯屬性。

  • pBmpUnchecked
    指定點陣圖提供尚未簽出的功能表項目使用。

  • pBmpChecked
    指定點陣圖為選取的功能表項目使用。

傳回值

如果不是零,則函式成功,則為 0。

備註

功能表項目是否已核取或取消核取,視窗在功能表項目旁顯示適當的點陣圖。

如果 pBmpUnchecked 或 pBmpChecked 是 NULL,則該視窗會在對應屬性的功能表項目旁顯示。 如果兩個參數都是 NULL, Windows 會使用預設的核取記號,當項目時會移除核取記號,當項目未核取時。

當終結功能表,就不會終結這些點陣圖,應用程式必須毀棄它們。

視窗 GetMenuCheckMarkDimensions 函式會擷取功能表項目的預設核取記號的維度。 應用程式會使用這些值來判斷點陣圖的適當大小提供此功能。 要取得其大小,建立自己的點陣圖,然後將它們。

範例

// The code fragment below is from CMainFrame::OnCreate and shows 
// how to associate bitmaps with the "Bitmap" menu item. 
// Whether the "Bitmap" menu item is checked or unchecked, Windows 
// displays the appropriate bitmap next to the menu item. Both 
// IDB_CHECKBITMAP and IDB_UNCHECKBITMAP bitmaps are loaded 
// in OnCreate() and destroyed in the destructor of CMainFrame class. 
// CMainFrame is a CFrameWnd-derived class.

// Load bitmaps from resource. Both m_CheckBitmap and m_UnCheckBitmap
// are member variables of CMainFrame class of type CBitmap.
ASSERT(m_CheckBitmap.LoadBitmap(IDB_CHECKBITMAP));
ASSERT(m_UnCheckBitmap.LoadBitmap(IDB_UNCHECKBITMAP));

// Associate bitmaps with the "Bitmap" menu item. 
CMenu* mmenu = GetMenu();
CMenu* submenu = mmenu->GetSubMenu(4);
ASSERT(submenu->SetMenuItemBitmaps(ID_MENU_BITMAP, MF_BYCOMMAND, 
   &m_CheckBitmap, &m_UnCheckBitmap));
// This code fragment is taken from CMainFrame::~CMainFrame

// Destroy the bitmap objects if they are loaded successfully 
// in OnCreate().
if (m_CheckBitmap.m_hObject)
   m_CheckBitmap.DeleteObject();

if (m_UnCheckBitmap.m_hObject)
   m_UnCheckBitmap.DeleteObject();

需求

Header: afxwin.h

請參閱

參考

CMenu 類別

階層架構圖

GetMenuCheckMarkDimensions

SetMenuItemBitmaps