(原) AutoIT应用:软件汉化的另类思路

原创文章,请后转载,并注明出处。

个人习惯,有中文就不用英文的;有绿色版就不用安装版。一个软件的语言配适程度,代表了友好程度,代表了客户的接受程度。虽然大多数时候,多看几遍也就认识了。

根据AutoIT可以读取、修改其它程序界面、控件的特点,我们可以拿它来做“软件汉化”工具。

此示例中,汉化了AutoIT自带的程序编辑器。这里仅是作了示例,并没有完全做完。而且也可以将汉化的内容做成汉化文件,通过程序读取修改。

另外,在菜单最后Help中添加了一项新功能。也应该可以添加响应程序,留待后面研究。

#include <GuiMenu.au3>

Dim $ProgClass = "[CLASS:SciTEWindow]"
Dim $ProgPath = "C:\Tools\AutoIT\SciTe\SciTE.exe"
Dim $ProgWnd, $menuMain, $menuCount

If WinExists($ProgClass) Then
	WinWaitActive($ProgClass)
Else
	RunWait($ProgPath)
EndIf

WinSetTitle($ProgClass,"","AutoIT 文档编辑器汉化版")
$ProgWnd = WinGetHandle($ProgClass)  							;窗口句柄
$menuMain = _GUICtrlMenu_GetMenu($ProgWnd)  			;菜单句柄
$menuCount = _GUICtrlMenu_GetItemCount($menuMain) ;菜单总数

Dim $menuFile,$menuHelp
$menuFile = _GUICtrlMenu_GetItemSubMenu($menuMain, 0)
; ConsoleWrite("Open item text: " & _GUICtrlMenu_GetItemText($menuMain, 0) & @CRLF)
; ConsoleWrite("Open item text: " & _GUICtrlMenu_GetItemText($menuFile, 18) & @CRLF)
_GUICtrlMenu_SetItemText($menuMain, 0, "文件(&F)")
_GUICtrlMenu_SetItemText($menuFile, 0, "新建(&N)	Ctrl+N")
_GUICtrlMenu_SetItemText($menuFile, 1, "打开(&O)	Ctrl+O")
_GUICtrlMenu_SetItemText($menuFile, 2, "打开所选文件名(&F)	Ctrl+Shift+O")
_GUICtrlMenu_SetItemText($menuFile, 3, "恢复(&R)	Ctrl+R")
_GUICtrlMenu_SetItemText($menuFile, 4, "关闭(&C)	Ctrl+W")
_GUICtrlMenu_SetItemText($menuFile, 5, "保存(&S)	Ctrl+S")
_GUICtrlMenu_SetItemText($menuFile, 6, "另存为(&A)	Ctrl+Shift+S")
_GUICtrlMenu_SetItemText($menuFile, 7, "保存副本(&Y)...	Ctrl+Shift+P")
_GUICtrlMenu_SetItemText($menuFile, 8, "复制路径(&H)")
_GUICtrlMenu_SetItemText($menuFile, 9, "编码(&G)")
_GUICtrlMenu_SetItemText($menuFile, 10, "导出(&E)")
_GUICtrlMenu_SetItemText($menuFile, 12, "页面设置(&U)...")
_GUICtrlMenu_SetItemText($menuFile, 13, "打印(&P)...  Ctrl+P")
_GUICtrlMenu_SetItemText($menuFile, 15, "加载会话(&L)...")
_GUICtrlMenu_SetItemText($menuFile, 16, "保存会话(&V)...")
_GUICtrlMenu_SetItemText($menuFile, 18, "退出(&X)")

$menuHelp = _GUICtrlMenu_GetItemSubMenu($menuMain, $menuCount-1)
$menuCount = _GUICtrlMenu_GetItemCount($menuHelp) ;菜单总数
_GUICtrlMenu_InsertMenuItem($menuHelp, $menuCount, "", 0x2001)
_GUICtrlMenu_InsertMenuItem($menuHelp, $menuCount+1, "关于汉化...", 0x2002)

小小的更新: 主动刷新菜单。添加菜单新项的另一方法。

#include <GuiMenu.au3>
#include <GUIConstantsEx.au3>

Dim $ProgClass = "[CLASS:SciTEWindow]"
Dim $ProgPath = "C:\Tools\AutoIT\SciTe\SciTE.exe"
Dim $ProgWnd, $menuMain, $menuCount

If WinExists($ProgClass) Then
	WinWaitActive($ProgClass)
Else
	RunWait($ProgPath)
EndIf

WinSetTitle($ProgClass,"","AutoIT 文档编辑器汉化版")
$ProgWnd = WinGetHandle($ProgClass)  							;窗口句柄
$menuMain = _GUICtrlMenu_GetMenu($ProgWnd)  			;菜单句柄
$menuCount = _GUICtrlMenu_GetItemCount($menuMain) ;菜单总数

Dim $menuFile,$menuHelp,$menuAbout
$menuFile = _GUICtrlMenu_GetItemSubMenu($menuMain, 0)
_GUICtrlMenu_SetItemText($menuMain, 0, "文件(&F)")
_GUICtrlMenu_SetItemText($menuFile, 0, "新建(&N)	Ctrl+N")
_GUICtrlMenu_SetItemText($menuFile, 1, "打开(&O)	Ctrl+O")
_GUICtrlMenu_SetItemText($menuFile, 2, "打开所选文件名(&F)	Ctrl+Shift+O")
_GUICtrlMenu_SetItemText($menuFile, 3, "恢复(&R)	Ctrl+R")
_GUICtrlMenu_SetItemText($menuFile, 4, "关闭(&C)	Ctrl+W")
_GUICtrlMenu_SetItemText($menuFile, 5, "保存(&S)	Ctrl+S")
_GUICtrlMenu_SetItemText($menuFile, 6, "另存为(&A)	Ctrl+Shift+S")
_GUICtrlMenu_SetItemText($menuFile, 7, "保存副本(&Y)...	Ctrl+Shift+P")
_GUICtrlMenu_SetItemText($menuFile, 8, "复制路径(&H)")
_GUICtrlMenu_SetItemText($menuFile, 9, "编码(&G)")
_GUICtrlMenu_SetItemText($menuFile, 10, "导出(&E)")
_GUICtrlMenu_SetItemText($menuFile, 12, "页面设置(&U)...")
_GUICtrlMenu_SetItemText($menuFile, 13, "打印(&P)...	Ctrl+P")
_GUICtrlMenu_SetItemText($menuFile, 15, "加载会话(&L)...")
_GUICtrlMenu_SetItemText($menuFile, 16, "保存会话(&V)...")
_GUICtrlMenu_SetItemText($menuFile, 18, "退出(&X)")

; 在最后一个菜单里添加新项
$menuHelp = _GUICtrlMenu_GetItemSubMenu($menuMain, $menuCount-1)
If _GUICtrlMenu_FindItem($menuHelp, "关于汉化...")==-1 Then
	_GUICtrlMenu_AddMenuItem($menuHelp, "")
	_GUICtrlMenu_AddMenuItem($menuHelp, "关于汉化...",$menuAbout)	
EndIf

_GUICtrlMenu_DrawMenuBar($ProgWnd)  ; 刷新菜单

相关文章