资源文件(.RES)的应用

- 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 可以是以下三种
Option Description
------ -----------
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.
- stringID  自行定义的integer,用来定义字串 resource.

- string    我们定义的字串,字串前後要用双引号(")将之包围起来,字串长度不可
            超过255 bytes,而且字串要在同一行 


BINARY RESOURCES
语法:

nameID keyword [load-option] [mem-option] filename

叁数:

- nameID 定义一个於以下keyword类别中,一个唯一的名称或数字,即,有三个BITMAP
         类别的Resource,其nameID可以分别为1,2,3不重覆,而另有三个ICON的资源
         ,其nameID亦可分别为1,2,3,不会和BITMAP的1,2,3相冲突。注:ICON类别
         的nameID不可以为0,0保留给 Visual Basic icon。nameID亦可以为字串
- keyword 定义资源类别
Option Description
------ -----------
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
Option Description
------ -----------
PRELOAD Resource is loaded immediately.
LOADONCALL (Default) Resource is loaded when called.

- mem-option
Option Description
------ -----------
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.
default for binary resources is MOVEABLE. - filename 资源所在的档名
 
Compiler的语法:

rc /r [options] SourceFile(.RC) 

- /r		只Compiler .RC file , not linked to any executable.

可用rc /? 来查语法

EXAMPLE

RC /r /fo TEST32.RES TEST.RC
上面的表格中是读取Test.RC的定义,而产生TEST32.RES,这个档便是我们程式设计中所需的资源档,而在vb5.0中如何来使用呢,在 "专案功能表 的 新增档案"中来选取该Resource file(.RES) ,之後在专案总管中,会出现
- ---Project1
   +-- 表单
   --- 相关文件
     |  
     ------TEST32.RES
那便可以使用 LoadResString LoadResPicture LoadResData来抓取相关的资料了 以下是Test.RC的内容,而BitMap, Icon写的档名,请自行更改成您对映的档案
#define IDS_HELLO    1
#define IDS_GOODBYE  2

STRINGTABLE
BEGIN
    IDS_HELLO,   "Hello"
    IDS_GOODBYE, "Goodbye"
    3,           "This is a Test"
END
STRINGTABLE
BEGIN
    101,        "您好"
    102,        "再见了"
    103,        "这是一个测试"
END

/////////////////////////////////////////////////
// Bitmap 
////////////////////////////////////////////////
1          BITMAP "CLI.BMP"
101        BITMAP "CLI2.BMP"
BITMAP3    BITMAP "多多.BMP"

////////////////////////////////////////////////
// ICON
///////////////////////////////////////////////
1          ICON   CLIENT.ICO

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

Private Sub Command1_Click()
Call ShowRtn(0)
End Sub

Private Sub ShowRtn(ByVal i As Long)
Label1.Caption = LoadResString(i + 1)
Label2.Caption = LoadResString(i + 2)
Label3.Caption = LoadResString(i + 3)
Set Picture1 = LoadResPicture(i + 1, vbResBitmap)
End Sub

Private Sub Command2_Click()
Call ShowRtn(100)
End Sub

Private Sub Command3_Click()
Set Picture1 = LoadResPicture("BITMAP3", vbResBitmap)
End Sub