Delphi Open Tools API - How to create and add new menu item
2008-01-23 10:47
711 查看
之前提介绍过如何编写一个菜单专家(Menu Wizard),但它有一个不足之处--就是我们所编写的菜单项只能作为Delphi IDE环境中的“Help”菜单的子项出现。如果我们想在Delphi IDE主菜单中任一位置插入我们自己的菜单项又应该如何做呢?
其实办法很简单,只需要编写一个插件专家(Add-in Wizard),在其构造函数中将菜单插入到Delphi IDE主菜单中,并在其析构函数中析构掉新插入的菜单项。
首先我们要在专家类中定义一些私有成员,用于保存Delphi IDE的主菜单,及我们新创建的菜单项。
FMainMenu: TMainMenu;
FNewMenuItem: TMenuItem;
接下来要做的就是在构造函数中获得Delphi IDE主菜单对象的实例,创建新菜单项并插入。
//Find Delphi's main menu
FMainMenu := (BorlandIDEServices as INTAServices) .MainMenu;
//Create new menu item
FNewItem := TMenuItem.Create(Nil);
FNewItem.Caption := 'Add-in Menu';
FNewItem.OnClick := MenuItemClick;
//Insert new menu item
FMainMenu.Items.Insert(FMainMenu.Items.Count - 1, FNewItem);
最后要在析构函数中释放掉我们插入的菜单项。
FMainMenu.Items.Remove(FNewItem);
FNewItem.Free;
其实办法很简单,只需要编写一个插件专家(Add-in Wizard),在其构造函数中将菜单插入到Delphi IDE主菜单中,并在其析构函数中析构掉新插入的菜单项。
首先我们要在专家类中定义一些私有成员,用于保存Delphi IDE的主菜单,及我们新创建的菜单项。
FMainMenu: TMainMenu;
FNewMenuItem: TMenuItem;
接下来要做的就是在构造函数中获得Delphi IDE主菜单对象的实例,创建新菜单项并插入。
//Find Delphi's main menu
FMainMenu := (BorlandIDEServices as INTAServices) .MainMenu;
//Create new menu item
FNewItem := TMenuItem.Create(Nil);
FNewItem.Caption := 'Add-in Menu';
FNewItem.OnClick := MenuItemClick;
//Insert new menu item
FMainMenu.Items.Insert(FMainMenu.Items.Count - 1, FNewItem);
最后要在析构函数中释放掉我们插入的菜单项。
FMainMenu.Items.Remove(FNewItem);
FNewItem.Free;
相关文章推荐
- How to add new item to the Context Menu
- How to add a menuitem in Nautilus context menu.
- How to Create a site at the specified URL and new database (Command-Line Operation)
- The robot API &&How to add and use sensor.
- Home not found. Define system property "openfireHome" or create and add the openfire_init.xml file to the classpath
- [转]NopCommerce How to add a menu item into the administration area from a plugin
- BOM API - uses the BOM_BO_PUB.PROCESS_BOM API to create bill header and add components to the bill
- How to add a new user in linux and add it to a new group
- How to add nested MenuItem dynamically
- OpenFiler Deployment [03]: How to create iSCSI partition and connection
- How to create a new user and grant permissions on MySql
- How to create Navigation Collection ,publish it as a pagelet and add to homepage ?
- How do I add classes to main menu ul and li in Drupal 8
- How To Create a New User and Grant Permissions in MySQL
- How to add nested MenuItem dynamically
- WinForms Controls > Examples > How to: Add New XtraForm, RibbonForm and XtraUserControl to Your Proj
- How To create Netbeans Platform and add to netbeans IDE by netbean platform manager
- How To Create a New User and Grant Permissions in MySQL
- SharePoint2013 Study Notes— How to Create a Event Receiver and Add Feature Event Receivers
- How To Defeat Advanced Malware. New Tools for Protection and Forensics