如何让自己的文本编辑器可以支持多国语言??

gpo2002 2003-11-19 09:27:46
word2000里面可以通过选择字体打开各国语言的文件
我用C/SDK做了一个文本编辑器,如何实现上面的功能??
功能:显示/编辑/保存
多谢先!
...全文
82 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
wenyongjie 2003-11-20
  • 打赏
  • 举报
回复
gpo2002(永吹不休):我贴出来的就是编译过的工程,是用CB写的,测试环境:
CB6.0+win2000.
你能不能给我一个可以编译通过的工程?是不是一个.exe文件?
gpo2002 2003-11-19
  • 打赏
  • 举报
回复
多谢楼上兄弟
但是我没有用过c++builder
说实话,看不太懂你的代码
你能不能给我一个可以编译通过的工程?
我的email:gpo2002@tom.com
多谢!
yesry 2003-11-19
  • 打赏
  • 举报
回复
只要计算好字高字宽,搞好菜单就行了。
wenyongjie 2003-11-19
  • 打赏
  • 举报
回复
接上:
void __fastcall TForm1::FormShow(TObject *Sender)
{
FindLanguages();
}
//---------------------------------------------------------------------------




void __fastcall TForm1::OKClick(TObject *Sender)
{
Form2->Show();
}
//---------------------------------------------------------------------------


void __fastcall TForm1::CancelClick(TObject *Sender)
{String ChildMenuName[2];
for(int i=0;i< LangMenu->Count;i++)
{ChildMenuName[i]=LangMenu->Items[i]->Caption;
ShowMessage(ChildMenuName[i]);
}
//(LangMenu->Count);//LangMenu->Items[0]->Caption

}
//---------------------------------------------------------------------------

记得给分
wenyongjie 2003-11-19
  • 打赏
  • 举报
回复
我有一个,编译时是可以通过的,给分吧
.H文件
//---------------------------------------------------------------------------

#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <Menus.hpp>
#include <inifiles.hpp> //加此头文件
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE-managed Components
TMainMenu *MainMenu1;
TMenuItem *LangMenu;
TButton *Cancel;
TButton *OK;
TLabel *Label1;
TGroupBox *GroupBox1;
TLabel *Label2;
TButton *Button1;
void __fastcall FormCreate(TObject *Sender);
void __fastcall FormShow(TObject *Sender);
void __fastcall OKClick(TObject *Sender);
void __fastcall CancelClick(TObject *Sender);
private: // User declarations
TStringList * ComponentNames;
TStringList * Captions;
String Language;
void __fastcall TForm1::LoadCaptions(TWinControl *Container, TIniFile *LangFile);
void __fastcall TForm1::RefreshCaptions(void);
void __fastcall TForm1::OnLanguageSelection(TObject *Sender);
void __fastcall TForm1::FindLanguages(void);

public: // User declarations
__fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif



CPP文件
//---------------------------------------------------------------------------
/*将TMainMenu控件的AutoHotKeys属性设置为maManual*/
#include <vcl.h>
#pragma hdrstop
#include "Unit2.h"
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;

//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::LoadCaptions(TWinControl *Container, TIniFile *LangFile) //利用控件数组实现文字转换
{
for (int i = 0; i < Container->ControlCount; i++)
{
if (dynamic_cast <TButton*>(Container->Controls[i])) // 包含在Form上如果是TButton按钮
{
TButton& ref_obj= dynamic_cast<TButton&>(*Container->Controls[i]);
String NewStr = LangFile->ReadString(Container->Name, ref_obj.Name, "");
if (strcmp(NewStr.c_str(), "")) ref_obj.Caption = NewStr;
}
if (dynamic_cast <TLabel*>(Container->Controls[i])) // 包含在Form上如果是 TLabel标签
{
TLabel& ref_obj = dynamic_cast<TLabel&>(*Container->Controls[i]);
String NewStr = LangFile->ReadString(Container->Name, ref_obj.Name, "");
if (strcmp(NewStr.c_str(), "")) ref_obj.Caption = NewStr;
}
else if (dynamic_cast <TGroupBox*>(Container->Controls[i])) //包含在GroupBox上的控件
{ // if it's a TGroupBox then load the panel's caption if any...
TGroupBox& ref_obj = dynamic_cast<TGroupBox&>(*Container->Controls[i]);
String NewStr = LangFile->ReadString(Container->Name, ref_obj.Name, "");
if (strcmp(NewStr.c_str(), "")) ref_obj.Caption = NewStr;
// and then call LoadCaptions() recursively to iterate through any
// objects contained in the GroupBox and update their captions or text...
LoadCaptions(&ref_obj, LangFile);
}

}
}
void __fastcall TForm1::RefreshCaptions(void)
{ if(Language=="中文") Language="Chinese";
else if(Language=="英文") Language="English";
ComponentNames->Clear();
Captions->Clear();
TIniFile * NewCaptions = NULL;
// Build our new captions filename...
String CaptionsFile = ExtractFilePath(Application->ExeName)+ Language + "_Captions.con";
// check to see if it exists in our application directory...
if (FileExists(CaptionsFile))
{
// if the file exists then create an instance of the inifile class
// and open the file for reading...
try
{
NewCaptions = new TIniFile(CaptionsFile);
}
catch(...)
{
ShowMessage("Error opening the " + Language + " captions file!");
}
}
else
{
// if the file doesn't exist then notify the user...
MessageDlg("Could not find " + Language + "_Captions.con" + " !!!",
mtError, TMsgDlgButtons() << mbOK, 0);
}
// if NewCaptions is valid then...
if (NewCaptions)
{
// Get the mainform and menu captions...
Form1->Caption = NewCaptions->ReadString("Form1", "FormCaption",
"Localizer"); //默认窗口标题Localizer FormCaption作为一个变量,详见.con文件内
LangMenu->Caption = NewCaptions->ReadString("Form1", "LangMenu",
"Language"); //默认语言菜单项标题Language
Form2->Caption=NewCaptions->ReadString("Form2","FormCaption","test2");

LangMenu->Items[0]->Caption=NewCaptions->ReadString("Form1", "ChildMenuName0","English");
LangMenu->Items[1]->Caption=NewCaptions->ReadString("Form1", "ChildMenuName1","Chinese");
// Step through all components on the form. If they have an entry in the
// NewCaptions file then load the value from the file into the caption of
// the component...
LoadCaptions(Form1, NewCaptions);
LoadCaptions(Form2, NewCaptions);
delete NewCaptions;
}
}
void __fastcall TForm1::OnLanguageSelection(TObject *Sender)
{
Language = ((TMenuItem*)Sender)->Caption;
RefreshCaptions();
}
void __fastcall TForm1::FindLanguages(void)
{
// searches the default directory for language files and
// creates a new menu item for each language it finds...
TMenuItem *LangMenu, *NewLangSelection;
TSearchRec sr;

// This is really unnecessary. Since we only have one top level menu item
// we could just set LangMenu = MainMenu1->Items->Items[0];
LangMenu = MainMenu1->Items->Items[MainMenu1->Items->Count - 1];

if (FindFirst("*_Captions.con", 0, sr) == 0)
{
// Create a new menu item...
NewLangSelection = new TMenuItem(LangMenu);
// Set it's caption to the first part of the language file's filename.
// (the part up to the underscore).
NewLangSelection->Caption = sr.Name.SubString(1, sr.Name.Pos("_") -1);
// se the new menu item's OnClick event to OnLanguageSelection.
NewLangSelection->OnClick = OnLanguageSelection;
// Insert the new menu item into the MainMenu
LangMenu->Insert(LangMenu->Count, NewLangSelection);
while (FindNext(sr) == 0)
{
// Do it all over again until we run out of language files.
NewLangSelection = new TMenuItem(LangMenu);
NewLangSelection->Caption = sr.Name.SubString(1, sr.Name.Pos("_") -1);
NewLangSelection->OnClick = OnLanguageSelection;
LangMenu->Insert(LangMenu->Count, NewLangSelection);
}
FindClose(sr);
}
}
void __fastcall TForm1::FormCreate(TObject *Sender)
{ ComponentNames = new TStringList;
Captions = new TStringList;

}
//---------------------------------------------------------------------------



1,221

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder Windows SDK/API
社区管理员
  • Windows SDK/API社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧