Most BCB programmers may not care about TOOLSAPI for a lifetime, but if bored like me,
You may wish to play and discuss:
Look at the following program to change the IDE to a sample:
--->bcb5. 0
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
useres ("Nodebug.res");
usepackage ("VCL50.BPI");
//---------------------------------------------------------------------------
#include <toolsapi.hpp>
#include <inifiles.hpp>
//---------------------------------------------------------------------------
#pragma package (smart_init)
//---------------------------------------------------------------------------
//Package source.
//---------------------------------------------------------------------------
namespace Nodebug//Here the namespace should is same with this file name.
{
bool needlocalize = true;
bool Needwritetoini = false;
tinifile *ini, *chsini;
ansistring section, Ident, Value;
//===[do something on MenuItems.] ======================================
void __fastcall DoMenuItem (tmenuitem* MenuItem)
{
//display all MenuItems.
if (menuitem->visible==false) menuitem->visible = true;
if (Needwritetoini &&! Menuitem->name.isempty ())
{
Ident = menuitem->name;
Value = menuitem->caption;
ini->writestring (section, Ident, Value);
}
}
//===[do something on MenuItems.] ======================================
//===[Enumerate all MenuItem ' s subitems.] ==============================
void __fastcall Enumeratemenuitem (tmenuitem* MenuItem)
{
DoMenuItem (MenuItem);
for (int i=0; i<menuitem->count; i++)
{
Enumeratemenuitem (Menuitem->items[i]);
}
}
//===[Enumerate all MenuItem ' s subitems.] ==============================
void __fastcall localizeappmenu ()
{
_di_intaservices IDE;
HRESULT hr = Borlandideservices->queryinterface (__uuidof (intaservices), (void * * *) &ide);
if (SUCCEEDED (HR))
{
//----------[Appbuilder macro start]--------------------------------------
#ifndef Appbuilder
#define Appbuilder Ide->mainmenu->owner
#endif
//----------[Appbuilder macro end]--------------------------------------
tstringlist* sectionlist = new Tstringlist;
tstringlist* identlist = new Tstringlist;
ansistring Value, Default ("NULL");
Try
{
chsini->readsections (sectionlist);
for (int i = 0; i < sectionlist->count; i++)
{
chsini->readsection (Sectionlist->strings[i], identlist);
for (int x = 0; x < identlist->count; x + +)
{
Value = chsini->readstring (Sectionlist->strings[i],
Identlist->strings[x],
"NULL");
if (Default!= Value)
{
tmenuitem* MI = dynamic_cast<tmenuitem*>
(Appbuilder->findcomponent (identlist->strings[x));
if (MI!= NULL) mi->caption = Value;
}
}
}
}
#undef Appbuilder
__finally
{
Delete identlist;
Delete sectionlist;
}
}
}
//===[BPL ' s ' Main ' function or Entry function.] ========================
void __fastcall PACKAGE Register ()
{
ini = new Tinifile (Changefileext (Application->exename, ". INI "));
Chsini = new Tinifile (Changefileext (Application->exename, "CHS.) INI "));
if (needlocalize) Localizeappmenu ();
_di_intaservices IDE;
HRESULT hr = Borlandideservices->queryinterface (__uuidof (intaservices), (void * * *) &ide);
if (SUCCEEDED (HR))
{
//----------[Appbuilder macro start]--------------------------------------
#ifndef Appbuilder
#define Appbuilder Ide->mainmenu->owner
#endif
----------[Appbuilder macro end]--------------------------------------
for (int i = 0; i<appbuilder->componentcount; i++)//Componentcount = 409
{
if (Appbuilder->components[i]->classnameis ("Tmainmenu"))//MainMenu1
{
//----------[Appmainmenu macro start]--------------------------------------
#ifndef Appmainmenu
#define Appmainmenu dynamic_cast<tmainmenu*> (Appbuilder->components[i])
#endif
//----------[Appmainmenu macro end]--------------------------------------
for (int x = 0; x < appmainmenu->items->count; x + +)//count 11
{
if (needwritetoini) section = appmainmenu->items->items[x]->name;
Enumeratemenuitem (appmainmenu->items->items[x]);
}//for finished.
#undef Appmainmenu
}//if finished.
}//for finished
#undef Appbuilder
}
Else ShowMessage ("error:i Can ' t Access ide.\nyou ' d better unload this module. ');
Delete ini;
Delete Chsini;
}
//===[BPL ' s ' Main ' function or Entry function.] ========================
}//namespace finished.
int WINAPI DllEntryPoint (hinstance hinst, unsigned long reason, void*)
{
return 1;
}
//---------------------------------------------------------------------------