生活随笔
收集整理的這篇文章主要介紹了
资源文件(.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 可以是以下三種 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 /? 來查語法EXAMPLERC /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 2STRINGTABLE
BEGINIDS_HELLO, "Hello"IDS_GOODBYE, "Goodbye"3, "This is a Test"
END
STRINGTABLE
BEGIN101, "您好"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 ExplicitPrivate Sub Command1_Click()
Call ShowRtn(0)
End SubPrivate 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 SubPrivate Sub Command2_Click()
Call ShowRtn(100)
End SubPrivate Sub Command3_Click()
Set Picture1 = LoadResPicture("BITMAP3", vbResBitmap)
End Sub
總結
以上是生活随笔 為你收集整理的资源文件(.RES)的应用 的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔 網站內容還不錯,歡迎將生活随笔 推薦給好友。