to:shenloqi,飘摇客
在两位的指导下制作窗体资源文件的问题已经解决,不知谁可以解释一以下这段代码?
帮我加加注释就行了:),以下这段代码是在由飘摇客提供的地址里下载的,由tao zhiyu
写的。先谢谢过
{
Title : MutilLanguage
Author : Taozhiyu
Email : taozhiyu@21cn.com
Homepage : http://www.angelfire.com/super/taozhiyu
}
unit MutilLanguage;
interface
uses
Registry, Forms, SysUtils, Windows, reinit;
function SwichLanguage(AForm : TForm ; Language : string) : boolean;
function ReadStr(StringID : integer) : string;
implementation
{$R Mystr.RES}
const
ENGLISH = (SUBLANG_ENGLISH_UK shl 10) or LANG_ENGLISH;
CHINESE = (SUBLANG_CHINESE_SIMPLIFIED shl 10) or LANG_CHINESE;
CurrentEnglish = 10;
CurrentChinese = 20;
function WriteRegistry(Name,Value:string):boolean;
var
RegisterTemp : TRegistry;
begin
result := false;
RegisterTemp := TRegistry.Create;
with RegisterTemp do
begin
try
RootKey:=HKEY_CURRENT_USER;
if OpenKey('Software/Borland/Locales',true) then
begin
WriteString(Name,Value);
result := true;
end;
CloseKey;
finally
Free;
end;
end;
end;
function ReadRegistry(Name : String): string;
var
RegisterTemp : TRegistry;
begin
result := '';
RegisterTemp := TRegistry.Create;
with RegisterTemp do
begin
try
RootKey:=HKEY_CURRENT_USER;
if OpenKey('Software/Borland/Locales',true) then
result:= ReadString(Name);
CloseKey;
finally
Free;
end;
end
end;
function CheckCurrentLanguage : integer;
begin
result := 0;
if ReadRegistry(Application.ExeName) = 'ENG' then
result := CurrentEnglish
else
result := CurrentChinese;
end;
function ReadStr(StringID : integer) : string;
var
txtCaption : array[0..255] of char;
begin
result := '';
StringID := StringID + CheckCurrentLanguage;
if LoadString(HInstance, StringID , txtCaption,SizeOf(txtCaption))>0 then
result:=StrPas(txtCaption);
end;
function RefreshFormFace(AForm : TForm ; Language : string) : boolean;
var
LoadSuccess : integer;
FormRect:TRect;
begin
result := false;
LoadSuccess := 0;
FormRect:=AForm.BoundsRect;
if Language = 'CHN' then LoadSuccess := LoadNewResourceModule(CHINESE);
if Language = 'ENG' then LoadSuccess := LoadNewResourceModule(ENGLISH);
if LoadSuccess <> 0 then
begin
LockWindowUpdate(AForm.Handle);
ReinitializeForms;
AForm.SetBounds(FormRect.Left,FormRect.Top,FormRect.Right-FormRect.Left,FormRect.Bottom-FormRect.Top);
LockWindowUpdate(0);
end;
result := true;
end;
function SwichLanguage(AForm : TForm ; Language : string) : boolean;
begin
result := false;
WriteRegistry(Application.ExeName , Language);
RefreshFormFace(AForm , Language);
result := true;
end;
end.