Using items from Resource Files |
|
axsoft
版主 ![]() ![]() ![]() ![]() ![]() ![]() 發表:681 回覆:1056 積分:969 註冊:2002-03-13 發送簡訊給我 |
Using items from Resource Files http://www.hobbypages.net/snip11.html
-------------------------------------------------------------------------------- Attached resource files (*.res) are the preferred way of storing changeable data in your project. Although you may be creating them with a variety of tools, and adding them to the main project CPP file or the individual forms, the advantage with C++ Builder, unlike Turbo C++, you can have more than one RES file. With that in mind, a rule of thumb - Don't touch any RES files created for you by the IDE/Builder. If you want to add resources, create a separate RES file and add #pragma resource "filename.res" to the form's header (right below the line #pragma resource "*.dfm"). If you put your resources into a separate DLL file, you can easily redistribute it to your users when you need to make changes. You can use the IMAGE EDITOR to compile stringtables, icons, bitmaps, and user-defined resources into usable RES files. Then build a DLL in these three easy steps: Step 1. Create a new project, using the Object Repository, and select a DLL type. Step 2. Use the IDE menu Project|Add to Project, and select your RES or RC file(s). The IDE knows what to do. Step 3. No other coding is needed. Build the project into a finished DLL. Rename it according to your needs. For this example it's mylibr.dll. Now, to use your items, you need a handle to the Library.
In the form's header add: private: //user declarations
HINSTANCE hLibHandle; In the form's constructor add:
__fastcall TForm1::TForm1(TComponent *Owner):TForm(Owner) { hLibHandle = LoadLibrary("mylibr.dll"); } And in the forms closing event: void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action) { if (hLibHandle != NULL) { FreeLibrary(hLibHandle); } }Well then, how 'bout some useful code? Examine this: [code] void __fastcall TForm1::FormCreate(TOBject *Sender) { if (hLiHandle != NULL) { char szBuffer[256]; LoadString(hLibHandle, 2001, szBuffer, 256); Label1->Caption = szBuffer; } } [/green] We just put a string into a label component at start-up, loaded from our DLL, assuming we numbered the stringID as 2001. Why not just write the string? What if it were 100 words, or a comment like UNREGISTERED USER that you wanted to change upon receipt of your hard earned money, by sending them a small DLL that replaces or removes the nag screens instead of just hiding them, or enabling disabled functionality. The same steps work, whether it's an icon, a bitmap, or any other user defined resource (just a few more steps with menus), whatever the DLL has stored for you. It'll keep your final EXE size reasonable as well. 網路志工聯盟----Visita網站http://www.vista.org.tw ---[ 發問前請先找找舊文章 ]--- |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |