下面是一个汉化菜单的例子。其中有得到菜单句柄的语句。<br>*************************************************<br>DELPHI:菜单的汉化<br><br>----现在我们经常看到一些软件汉化包,例'晴窗伴侣'是PHOTOSHOP<br>的汉化包,其实我们只要对WINDOWS的编程熟悉,也可以自己编写某<br>些软件的汉化包。这样不管软件大小,只要你喜欢就可以给做一个汉<br>化包。下面的程序是一些主要的步骤。其实你还可以用别的方法来实<br>现,亲自试试吧。<br><br>----在运行程序之前首先生成一个中英文菜单对照表文件,产生时可<br>以参照该程序自己编制一个获得系统的原菜单内容的程序,然后在之<br>后输入菜单的汉字内容。其格式如下:<br> <br>SAVE AS 保存到.... <br>. . <br>.. <br>EXIT 退出系统 <br>// 程序开始 <br>unit wrdxt; <br><br>interface <br><br>uses <br>Windows, Messages, SysUtils, Classes, <br>Graphics, Controls, Forms, Dialogs, <br>StdCtrls; <br><br>type <br>TForm1 = class(TForm) <br>Button1: TButton; <br>ListBox1: TListBox; <br>ListBox2: TListBox; <br>procedure Button1Click(Sender: TObject); <br>procedure FormActivate(Sender: TObject); <br>private <br>{ Private declarations } <br>public <br>{ Public declarations } <br>end; <br>var <br>Form1: TForm1; <br>childmenu,mainmenu,c2menu:hmenu; <br>wndhandle:hwnd; <br>mystr
char; <br>mainnum,childNUM,c2num:integer; <br>MYCHAR:STRING; <br>mm3,mm6:string[19]; <br>mm4,mm5:string; <br>implementation <br><br>{$R *.DFM} <br>//我用表单的CLICK事件激活,其实用ACTIVE事件会更好<br>procedure TForm1.Button1Click(Sender: TObject); <br>var <br>start1,start2,start3,start4,start5:integer; <br><br>begin <br>//通过标题获得窗口句柄 <br>wndhandle:=findwindow(nil,mystr); <br>//通过标题获得菜单句柄 <br>mainmenu:=getmenu(wndhandle); <br>//取得顶行菜单数 <br>mainnum:=getmenuitemcount(mainmenu); <br>//汉化菜单 <br>for start1:=0 to mainnum do <br>begin <br>mm5:=``; <br>//取得菜单项的标题 <br>getmenustring(mainmenu,start1,PCHAR <br>(myChAR),20,MF_BYPOSITION); <br>mm6:=string(pchar(mychar)); <br>for start3:=0 to listbox1.items.count-1 do <br>begin <br>mm4:=listbox1.Items[start3]; <br>mm3:= mm4; <br>if (string(mm6)=trim(mm3)) then <br>begin <br>for start4:=21 to length(mm4) do <br>begin <br>mm5:=mm5+mm4[start4]; <br>end; <br>end; <br>end; <br>if mm5<>`` then <br>modifymenu(mainmenu,start1,MF_BYPOSITION, <br>getmenuitemid(mainmenu,start1),pchar(mm5)); <br>childmenu:=getsubmenu(MAINMENU,start1); <br>childnum:=getmenuitemcount(childmenu); <br>//汉化下拉菜单 <br>for start2:=0 to childnum do <br>begin <br>mm5:=``; <br>getmenustring(childmenu,start2,PCHAR <br>(mychar),20,MF_BYPOSITION); <br>mm6:=string(pchar(mychar)); <br>for start3:=0 to listbox1.items.count-1 do <br>begin <br>mm4:=listbox1.Items[start3]; <br>mm3:= mm4; <br>if (string(mm6)=trim(mm3)) then <br>begin <br>for start4:=21 to length(mm4) do <br>begin <br>mm5:=mm5+mm4[start4]; <br>end; <br>end; <br>end; <br>if mm5<>`` then <br><br>modifymenu(childmenu,start2,MF_BYPOSITION, <br>getmenuitemid(childmenu,start2),pchar(mm5)); <br>c2menu:=getsubmenu(childMENU,start2); <br>c2num:=getmenuitemcount(c2menu); <br>for start5:=0 to c2num do <br>begin <br>mm5:=``; <br>getmenustring(c2menu,start5,PCHAR <br>(mychar),20,MF_BYPOSITION); <br>mm6:=string(pchar(mychar)); <br>for start3:=0 to listbox1.items.count-1 do <br>begin <br><br>mm4:=listbox1.Items[start3]; <br>mm3:= mm4; <br>if (string(mm6)=trim(mm3)) then <br>begin <br>for start4:=21 to length(mm4) do <br>begin <br>mm5:=mm5+mm4[start4]; <br>end; <br>end; <br>end; <br>if mm5<>`` then <br>modifymenu(c2menu,start5,MF_BYPOSITION, <br>getmenuitemid(c2menu,start5),pchar(mm5)); <br>END; <br><br>END; <br>end; <br><br>end; <br><br>procedure TForm1.FormActivate(Sender: TObject);<br>begin <br>//要汉化的系统的窗口标题 <br>//mystr:=`adobe photoshop`; <br>mystr:=`frontpage explorer`; <br>mychar:=` `; <br>//装入已编辑好的中英文菜单对照文件 <br>listbox1.items.loadfromfile(`myfile2.txt`);<br>end; <br><br>end. <br><br>