OnAnnMenu example for C++ Builder
// This Example is for also for:
// Count Property, ItemString Property, ItemID Property, ItemType Property,
// ItemChecked Property, ItemEnabled Property, DeleteItem method,
// AddItem method, GetSubMenu method, OnAnnUserMenu event
void __fastcall TForm1::LEADAnn1AnnMenu(TAnnMenu *AnnMenu)
{
int nID;
int x;
TAnnMenu * PopupMenuItem;
AnsiString Msg;
Msg= "There are " + IntToStr (AnnMenu->Count) + " Items";
ShowMessage (Msg);
Msg= "Original Text for item#2: " + AnnMenu->ItemString [1];
ShowMessage (Msg);
//set new string
AnnMenu->ItemString [1]= "TestText";
Msg= "Custom Text for item#2: " + AnnMenu->ItemString [1];
ShowMessage (Msg);
//make 3rd and 4th menu items have the same command id
nID= AnnMenu->ItemID[3];
AnnMenu->ItemID [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 < AnnMenu->Count - 1; x ++ )
{
if ( AnnMenu->ItemType[x] == ANNMENUITEMTYPE_NORMAL )
{
if (AnnMenu->ItemChecked [x] == false)
AnnMenu->ItemChecked [x]= true;
if (AnnMenu->ItemEnabled[x]== true)
AnnMenu->ItemEnabled [x]= false;
}
}
//insert 2 user-defined menu items
AnnMenu->AddItem ("&Flip", ANNMENUITEMTYPE_NORMAL, LTANNEVENT_MENUFIRST, AnnMenu->Count);
AnnMenu->AddItem ("Test&2", ANNMENUITEMTYPE_NORMAL, LTANNEVENT_MENUFIRST + 1, AnnMenu->Count);
//delete the last menu item
AnnMenu->DeleteItem (AnnMenu->Count - 1);
//delete the first menu item
AnnMenu->DeleteItem (0);
//insert a popup menu
AnnMenu->AddItem ("&Popup1", ANNMENUITEMTYPE_SUBMENU, 0, AnnMenu->Count);
//get the new item, and add some items to it
PopupMenuItem= AnnMenu->GetSubMenu(AnnMenu->Count - 1);
PopupMenuItem->AddItem ("Test&1", ANNMENUITEMTYPE_NORMAL, LTANNEVENT_MENUFIRST + 2, PopupMenuItem->Count);
PopupMenuItem->AddItem ("Test&2", ANNMENUITEMTYPE_NORMAL, LTANNEVENT_MENUFIRST + 3, PopupMenuItem->Count);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::LEADAnn1AnnUserMenu (int nID)
{
AnsiString Msg;
if (nID == LTANNEVENT_MENUFIRST)
LEADAnn1->AnnFlip (false, 0, true);
else
{
Msg= "nID = LTANNEVENT_MENUFIRST + " + IntToStr (nID - LTANNEVENT_MENUFIRST);
ShowMessage (Msg);
}
}