AnnMenu example for C++ 5.0 and later
For details on event handling of the COM objects in MFC, and m_pDlg and m_pRasterAnn declarations, refer to the "Creating and Using Annotations (C++ 5.0 and later) Tutorial"
//The AnnMenu event occurs just before an annotation automation menu is displayed.
//This example:
//* Displays the number of menu items
//* Changes the text of a menu item
//* Checks all unchecked menu items
//* Disables all menu items
//* Adds a user defined menu item (flip)
//* Adds a user defined popup menu
//
//For details on event handling of the COM objects in MFC,
// and m_pDlg and m_pRasterAnn delcarations, refer to
// the "Creating and Using Annotations (C++ 5.0 and later) Tutorial"
void CRasterAnnSink::OnAnnMenu(long hMenu)
{
long nID;
short x;
CString strMsg;
ILEADRasterAnnMenu *pRasterAnnMenu = NULL;
HRESULT hr = CoCreateInstance(
CLSID_LEADRasterAnnMenu,
NULL,
CLSCTX_ALL,
IID_ILEADRasterAnnMenu,
(void**)&pRasterAnnMenu
);
if (SUCCEEDED(hr) && (pRasterAnnMenu != NULL) )
{
pRasterAnnMenu->SetAnnMenu(hMenu);
strMsg.Format(TEXT("There are %ld Items"), pRasterAnnMenu->GetCount());
AfxMessageBox(strMsg);
strMsg.Format(TEXT("Original Text for item#2: %s"), (LPCTSTR)pRasterAnnMenu->GetItemString(1));
AfxMessageBox(strMsg);
//set new string
pRasterAnnMenu->PutItemString(1, TEXT("TestText"));
strMsg.Format(TEXT("Custom Text for item#2: %s"), (LPCTSTR)pRasterAnnMenu->GetItemString(1));
AfxMessageBox(strMsg);
//make 3rd and 4th menu items have the same command id
nID = pRasterAnnMenu->GetItemID(3);
pRasterAnnMenu->PutItemID(2, nID);
//check all unchecked menu items that are not popup submenus
//disable all enabled menu items that are not popup submenus
for(x=0; x<pRasterAnnMenu->GetCount(); x++)
{
if(pRasterAnnMenu->GetItemType(x) == ANN_MENUITEMTYPE_NORMAL)
{
if(!pRasterAnnMenu->GetItemChecked(x))
pRasterAnnMenu->PutItemChecked(x, TRUE);
if(pRasterAnnMenu->GetItemEnabled(x))
pRasterAnnMenu->PutItemEnabled(x, FALSE);
}
}
//insert 2 user-defined menu items
pRasterAnnMenu->AddItem("&Flip", ANN_MENUITEMTYPE_NORMAL, ANN_EVENT_MENUFIRST, pRasterAnnMenu->GetCount());
pRasterAnnMenu->AddItem("Test&2", ANN_MENUITEMTYPE_NORMAL, ANN_EVENT_MENUFIRST + 1, pRasterAnnMenu->GetCount());
//delete the last menu item
pRasterAnnMenu->DeleteItem(pRasterAnnMenu->GetCount() - 1);
//delete the first menu item
pRasterAnnMenu->DeleteItem(0);
//insert a popup menu
pRasterAnnMenu->AddItem("&Popup1", ANN_MENUITEMTYPE_SUBMENU, 0, pRasterAnnMenu->GetCount());
//get the new item, and add some items to it
ILEADRasterAnnMenu *pPopupMenuItem = NULL;
pRasterAnnMenu->GetSubMenu(pRasterAnnMenu->GetCount() - 1, &pPopupMenuItem);
pPopupMenuItem->AddItem("Test&1", ANN_MENUITEMTYPE_NORMAL, ANN_EVENT_MENUFIRST + 2, pPopupMenuItem->GetCount());
pPopupMenuItem->AddItem("Test&2", ANN_MENUITEMTYPE_NORMAL, ANN_EVENT_MENUFIRST + 3, pPopupMenuItem->GetCount());
//pPopupMenuItem->Release();
pRasterAnnMenu->Release();
}
}
void CRasterAnnSink::OnAnnUserMenu(long nID)
{
if (nID == ANN_EVENT_MENUFIRST)
{
m_pDlg->m_pRasterAnn->AnnFlip(FALSE, 0.0f, TRUE);
}
else
{
CString strMsg;
strMsg.Format(TEXT("nID = ANN_EVENT_MENUFIRST + %d"), nID - ANN_EVENT_MENUFIRST);
AfxMessageBox(strMsg);
}
}