Play the BCB IDE and experience TOOLSAPI

Source: Internet
Author: User
Tags bool ini

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;


}

//---------------------------------------------------------------------------

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.