SetMenuItemBitmaps

SetMenuItemBitmaps,函式名稱,如果調用成功會返回非零值,否則為0.

簡介,參數,

簡介

CMenu::SetMenuItemBitmaps
BOOLSetMenuItemBitmaps(UINTnPosition,UINTnFlags,constCBitmap*pBmpUnchecked,constCBitmap*pBmpChecked);
返回值:如果調用成功會返回非零值,否則為0.

參數

第一個參數nPosition的取值由第二個參數nFlags的取值決定。如果第二個參數的取值為MF_BYPOSITION,即使用位置索引,那么第一個參數為選單項位置索引;如果第二個參數的取值為MF_BYCOMMAND,那么第一個參數為選單項標示,應該使用該選單項的ID。後兩個參數都是CBitmap類的指針,用來設定與選單項關聯的兩個點陣圖,其中第三個參數表示該選單項未被選中時的點陣圖,第四個參數表示該選單項被選中之後的顯示的點陣圖。
Example
// The code fragment below shows how to associate bitmaps with the
// "Test" menu item. Whether the "Test" 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.
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CFrameWnd::OnCreate(lpCreateStruct) == -1) return -1;
// 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 "Test" menu item.
CMenu* mmenu = GetMenu();
CMenu* submenu = mmenu->GetSubMenu(3);
ASSERT(submenu->SetMenuItemBitmaps(ID_HELP_TEST, MF_BYCOMMAND, &m_CheckBitmap, &m_UnCheckBitmap)); // ...
}
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();
}

熱門詞條

聯絡我們