天天看点

资源文件(.RES)的应用

资源档有什麽用处呢?最重要的有两个地方

1.国际发行:我们将Application中所有的文字从Resource用读取,那麽,只要更动

            Resource档的内容,就可以用不同语言的方式来显示。

2.管理资源:例如说,我们的AP中用了数百张的图片或声音,不用Resource档的话,

            在发行出去的AP中,就必需有数百个图形、声音档,那似乎不太好,使

            用Resource档,便可以将这些图形、声音放进一个.Res档。

使用RC.exe来Compiler我们所定义的Resource档, RC.EXE在vb5.0光碟中的/TOOLS/RESOURCE 

Resources 可分成两大部份:

- String resources (text strings such as "Hello World").

- Binary resources (icons, bitmaps, cursors, sounds, video等)

String Resources

语法:

STRINGTABLE [load-option] [mem-option]

BEGIN

stringID string

.

    .

END

叁数说明 :

- load-option 可以是以下两种

Option

Description

------

-----------

PRELOAD

Resource is loaded immediately.

LOADONCALL

(Default) Resource is loaded when called.

- mem-option 可以是以下三种

FIXED

Resource remains at a fixed memory location.

MOVEABLE

Resource can be moved if necessary in order to compact memory.

DISCARDABLE

Resource can be discarded if no longer needed.

- keyword 定义资源类别

BITMAP

Defines a bitmap (.BMP)

CURSOR

Defines a cursor (.CUR)

ICON

Defines an icon (.ICO)

SOUND

Defines a wave file (.WAV)

VIDEO

Defines a video file (.AVI)

- load-option

- mem-option

default for binary resources is MOVEABLE. - filename 资源所在的档名

上面的表格中是读取Test.RC的定义,而产生TEST32.RES,这个档便是我们程式设计中所需的资源档,而在vb5.0中如何来使用呢,在 "专案功能表 的 新增档案"中来选取该Resource file(.RES) ,之後在专案总管中,会出现

那便可以使用 LoadResString LoadResPicture LoadResData来抓取相关的资料了 以下是Test.RC的内容,而BitMap, Icon写的档名,请自行更改成您对映的档案

以下是在form中,需3个Command Button 3个Label 1个PictureBox 另需在 专案功能表 中选 新增档案 并进而选取Test32.Res