Creation and use of resource files

xiaoxiao2021-03-06  50

Creation and use of resource files

1. Creating a resource file first creates a .rc plain text file. The format is as follows: Resource Identifier Keyword Resource File Name (1) Resource Identifier: Special Number When Calling Resources; (2) Keywords: Identify Resource File Types; Wave: Resource Files are sound files; RCData: JPEG file; avi: avi animation; icon: icon file; Bitmap: bitmap file; Cursor: cursor file; resource file name: Resource file name; (3) Resource file name: Compiled resource files, such as animation, bitmap, Cursor, etc. (4) such as: MyWav Wave "FileName.wav" transforms .rc files using the Borland resource compiler (Brcc32.exe) .res file. Enter the following command in the DOS command line: brcc32 filename.rc // brcc32.exe under Delphi5 / bin file. 2. Quote Resource Documents in Engineering In order to access our resource files, you must tell Delphi link our resource files to the application. Therefore, we can add a compile instruction to complete the above function in the source code. This instruction must follow the window instruction, as follows: {$ r * .dfm} file: // Delphi comes with compile instruction {$ r filename.res} file: // The newly added compiler file instruction. Do not delete {$ r * .dfm} instructions, because this line code tells the Delphi link below the resource of the window. 3. Call Resource Files (1) If you want to access resources in a bitmap program in your resource file, you must call some Windows API functions. The bitmaps, cursors, and icons saved in the resource file can be accessed by calling the LoadBitmap, LoadCursor, and Loadicon functions. This example exemplifies how to access the resource file median and display it in the TIMAGE control. Procedure tfrmain.btncanvaspic (sender: TOBJECT); Image1.Picture.bitmap.Handle: = loadingBitmap (Hinstance, 'resource identifier'); end; Note: If the bitmap is not loaded, the program is still executed, but the image will no longer display image. You can determine whether the load is successful according to the return value of the loadbitmap function. If the load success return value is non-0, if the load failed return value is 0. Another method of accessing display bitmaps The following procedure tfrMain.btnloadPICClick (Sender: TOBJECT); begin image1.picture.bitmap.loadfromResourceName (Hinstance, 'resource identifier'); end; (2) Access the cursor in the resource file Screen.cursors [] is a cursor array that uses cursor files we can add custom cursors to this property. Because the default cursor is 0 in array, the index value is 0, so it is best to set the custom cursor index to 1 unless you want to replace the default cursor. Procedure tfrMain.btnusecursorclick (sender: TOBJECT); Begin Screen.cursors [1]: = loading, 'resource identifier'); image1.cursor: = 1; end; (3) Acquisition of icons in the resource file The icon is placed in the resource file and dynamically change the application icon.

转载请注明原文地址:https://www.9cbs.com/read-115543.html

New Post(0)