這應該是一個使用VC的一個小技巧,不過在打算做之前,在網上找了找,沒有找到(可能是我填入的關鍵字不對,:-)),所以在這里給大家提供一個參考,希望對大家能提供方便,不用象我找的這么辛苦。
意圖:實現多種語言在同一個工程里,如果調試成功后,即可以同時編譯程序的多種語言版本。
平臺:Win2000 Pro SP4, VC++6.0,SDK
一般情況下,編寫程序都會使用工程制作向導,生成的工程有兩個編譯版本,一個是Debug,另外一個就是Release,我的目的就是添加多種語言的編譯版本,同時需要多種語言的.rc文件(Source文件),然后經過一些簡單的設置,就Okay了。
?????? 我添加很多的圖片,這樣比較容易理解,也少去讀文字的痛苦(用電腦看大篇大篇的文字真的很痛苦)。
? 下面我們開始:
?
1.
首先是以工程文件里的.rc文件為基礎,制作多種語言的.rc文件,就是把有關對話框,屬性頁,以及一些ID文字替換為其他的語言文字,這里需要注意的
是,不同語言版本的.rc文件,包含很多相同的圖標(Icon),對話框(Dialog),String
Table,在VC編譯器的SourceView里都要選擇相應的語種。比如:如果是English,以上說的這些都要選擇English(U.S.)。
? 2. 添加多語言編譯版本,選擇Build->Configurations,點擊Add,添加相應的語言編譯版本,我這里添加的是English Release。隨后添加多種語言版本。
添加多種語言的編譯版本
? 3. 編輯不同語言版本的Project Setting。點擊菜單Project->Settings,修改相應的設置
設置Output directories: 包括Intermediate和Output files,我這里都設置為English Release
設置Output file name: 我這里設置為English_Release/ktrexe.exe
設置Language:英語(美國)?????
?
4. 添加Source Files
?
添加后會彈出一個對話框,不用理會它
此時你可以在你編譯器的ResourceView里看到:
?
以后如果需要修改不同的語言,可以修改相應的resources文件。
5. 點擊Project->Settings,點擊你所點擊的.rc文件
?
選中Exclude file from build
?
選擇“是”,每一種.rc文件分別選取相應的語言編譯版本,比如Win32 English Release,選擇Winapp1_English.rc,然后在Exclude file from build打勾即可。
?
6. 編譯:
選擇Build->Batch Build
?
選中您所要編譯的語種,選中Selection only,點擊Rebuild All即可。
?
7. 此時,您可以看到您的.dsp文件已經被修改。
?
?????? 我曾經在CSDN論壇上問過此問題,還有不同的解法,我把他們帖出來:
?
??? 我的操作是在VC++6.0里有一個用Win32程序向導生成的一個工程,此工程代碼添加,調試,運行都已經Okay。
??? 由于該工程是簡體中文的,我想添加其他的語言版本,我就在.rc復本的基礎上把簡體中文的項目換成了其他的語言(比如西班牙語),然后我在Build->Configurations里添加了Spanish Release,在Project-〉Settings里設置了語言環境,輸入路徑等等屬性。隨后我就在Project-〉Add Files添加我剛才更換語言的.rc文件添加進來。
??? 目的是用Debug調試,然后在Build-〉Batch Build選項里選擇我要編譯的語言種類,一次編譯多種語言。
??? 問題是VC6.0提示說“Multiple.rc
files exist in this project. Only one can be marked as included in the
build. The others will be excluded frome the build.”
??? 請問,如何解決這個問題,我在網上找了兩天了,在其他的Newsgroups上法帖,沒有找到答案,是不是我哪里設置錯了,請高手給個提示。謝謝!
把你現在的.rc保存,然后把所有的中文換成其他語言,別存為其他other.rc。
GetResourceInstance()得到資源句柄。換成另other.rc,(SetResourceHandle)
就可以搞定。
因為所有的id沒變,所有程序都能正常運行。
最好把資源做成dll,用LoadResource切換
寫成INI也是一個好辦法!
?
其他論壇的回答:
Several solutions:
1. Place all your resources into one big. rc file.
2. Exclude the additional rc files from the build and include them by the
resource includes (right mouse click on the resource file in the resource
editor). In this case you have to take care that bitmaps and others are only
included once!
3. Create seperate DLL's for each language and use the corresponding handle
to this DLL when loading resources. Read the docu to AfxSetResourceHandle
when you are using the MFC.
1)????? use the "resource includes" menu item in VC C++ 6.0 and include one
resource in the other (i.e. #include "file.rc")? Make sure that there are no
conflicts and each resource is properly marked with the correct language.
Mark the RC file as excluded from the build.? It will get built anyway since
it was included in the main RC.
2)????? have separate DLL (i.e. a separate sub-project) for each RC file (the
satellite DLL approach to localization)
If you are unhappy with having separate builds for each language then
you'll have to combine the .rc files with (or without if they doesn't use
same identifiers) the proper LANGUAGE ID #ifdef's. If you don't know
about these, use the Resource editor built into the Environment to create
a new .rc with element variants in several languages. Then open the file
and analyse it.
In VS.NET 2003 click on Build>Configuration Manager
You will find your project. Now it is possible to select New in the combo
"Active Solution Configuration" you can add new settings to the current ones
Debug/Release.
In VS6 click on Build->Configurations. You will find your project displayed
as a tree. Click on Add to add new configurations.
In both caes you will be asked what base configuratin should be copied.
Now you can create different Release modes like German/English/Bavarian and
so on...
For each configuration you can define diffrent rc files to be excluded from
the build. Also you can define different output directories.
The disadvantage is that you always have a complete binary for a language
and you can not switch the language on user request!
?
?
如果有問題,請和我聯系:danielxu22@cellink.com.cn