Third-Party Help Menu Item (C++)
Contents
Description
The following package implementation file uses the ToolsAPI to add a menu item ("My Company") to the Help > Third-Party Help menu of the IDE, and then add two child menu items to that new menu item:
- "Offline Help", which opens a CHM file.
- "Online Help", which opens a web page.
To use this code example:
- Create a design-time package that is configured to use the Tools API.
- Replace the content of the package implementation file (
Package1.cpp
) with the source code below. - Replace
"Path\\to\\your\\local\\help\\file"
with the actual path to your help file. The code is meant to work with a CHM file, but other file formats should work as well. - Replace
"http://example.com"
with the main URL of your help.
Code
// Package1.cpp
//---------------------------------------------------------------------------
#include <System.hpp>
#include <System.SysUtils.hpp>
#include <ToolsAPI.hpp>
#include <Vcl.Menus.hpp>
#include <Winapi.ShellAPI.hpp>
#include <Winapi.Windows.hpp>
#pragma hdrstop
#pragma package(smart_init)
//---------------------------------------------------------------------------
// Package source.
//---------------------------------------------------------------------------
struct TMyIdeExtension {
_di_INTAServices NTAServices;
TMenuItem* MyHelpMenuItem;
TMenuItem* MyOfflineHelpMenuItem;
TMenuItem* MyOnlineHelpMenuItem;
void OpenLocalFile(UnicodeString Path) {
if (FileExists(Path)) {
TShellExecuteInfo SEInfo = { 0 };
SEInfo.cbSize = sizeof(TShellExecuteInfo);
SEInfo.hwnd = 0;
SEInfo.lpFile = Path.w_str();
SEInfo.lpParameters = NULL;
SEInfo.nShow = SW_SHOWDEFAULT;
SEInfo.lpVerb = L"open";
SEInfo.lpDirectory = ExtractFileDir(Path).w_str();
ShellExecuteExW(&SEInfo);
}
}
void OpenUrl(UnicodeString Url) {
TShellExecuteInfoW SEInfo = { 0 };
SEInfo.cbSize = sizeof(TShellExecuteInfo);
SEInfo.hwnd = 0;
SEInfo.lpFile = Url.w_str();
SEInfo.lpParameters = NULL;
SEInfo.nShow = SW_SHOWDEFAULT;
SEInfo.lpVerb = L"open";
SEInfo.lpDirectory = NULL;
ShellExecuteExW(&SEInfo);
}
void __fastcall OfflineHelpClick(TObject* Sender) {
OpenLocalFile("Path\\to\\your\\local\\help\\file");
}
void __fastcall OnlineHelpClick(TObject* Sender) {
OpenUrl("http://example.com");
}
TMyIdeExtension() {
if (BorlandIDEServices->Supports(NTAServices)) {
TMenuItem* MyHelpMenuItem = new TMenuItem(NULL);
MyHelpMenuItem->Name = "MyCompanyHelpMenuItem";
MyHelpMenuItem->Caption = "MyCompany";
MyHelpMenuItem->ImageIndex = 16;
NTAServices->AddActionMenu("HelpThirdPartyMenuItem", NULL, MyHelpMenuItem, false, true);
TMenuItem* MyOnlineHelpMenuItem = new TMenuItem(MyHelpMenuItem);
MyOnlineHelpMenuItem->Caption = "Online Help";
MyOnlineHelpMenuItem->ImageIndex = 153;
MyOnlineHelpMenuItem->OnClick = OnlineHelpClick;
NTAServices->AddActionMenu("MyCompanyHelpMenuItem", NULL, MyOnlineHelpMenuItem, false, true);
TMenuItem* MyOfflineHelpMenuItem = new TMenuItem(MyHelpMenuItem);
MyOfflineHelpMenuItem->Caption = "Offline Help";
MyOfflineHelpMenuItem->ImageIndex = 16;
MyOfflineHelpMenuItem->OnClick = OfflineHelpClick;
NTAServices->AddActionMenu("MyCompanyHelpMenuItem", NULL, MyOfflineHelpMenuItem, false, true);
}
}
~TMyIdeExtension() {
delete MyHelpMenuItem;
}
};
TMyIdeExtension MyIdeExtension;
#pragma argsused
extern "C" int _libmain(unsigned long reason)
{
return 1;
}
//---------------------------------------------------------------------------
Uses
- Vcl.Menus.TMenuItem ( fr | de | ja )
- System.SysUtils.Supports ( fr | de | ja )
See Also
- Third-Party Help Menu Item (Delphi) code example