用_GUICtrlMenu_InsertMenuItem创建中文菜单会少字?
用_GUICtrlMenu_InsertMenuItem创建中文菜单时,中文只能显示一半,有时还会出现乱码,这是怎么回事?用GUICtrlCreateMenuItem创建中文菜单是正常的
#include <GuiMenu.au3>
#include <GuiConstantsEx.au3>
Opt('MustDeclareVars', 1)
_Main()
Func _Main()
Local $hGUI, $hFile, $hEdit, $hHelp, $hMain
Local Enum $idNew = 1000, $idOpen, $idSave, $idExit, $idCut, $idCopy, $idPaste, $idAbout
; Create GUI
$hGUI = GUICreate("Menu", 400, 300)
; Create File menu
$hFile = _GUICtrlMenu_CreateMenu ()
_GUICtrlMenu_InsertMenuItem ($hFile, 0, "中文中文中文", $idNew)
_GUICtrlMenu_InsertMenuItem ($hFile, 1, "&Opendfddfsdsfdsfds", $idOpen)
_GUICtrlMenu_InsertMenuItem ($hFile, 2, "&Save", $idSave)
_GUICtrlMenu_InsertMenuItem ($hFile, 3, "", 0)
_GUICtrlMenu_InsertMenuItem ($hFile, 4, "E&xit", $idExit)
; Create Edit menu
$hEdit = _GUICtrlMenu_CreateMenu ()
_GUICtrlMenu_InsertMenuItem ($hEdit, 0, "&Cut", $idCut)
_GUICtrlMenu_InsertMenuItem ($hEdit, 1, "C&opy", $idCopy)
_GUICtrlMenu_InsertMenuItem ($hEdit, 2, "&Paste", $idPaste)
; Create Help menu
$hHelp = _GUICtrlMenu_CreateMenu ()
; Create Main menu
$hMain = _GUICtrlMenu_CreateMenu ()
_GUICtrlMenu_InsertMenuItem ($hMain, 0, "&File", 0, $hFile)
_GUICtrlMenu_InsertMenuItem ($hMain, 1, "&Edit", 0, $hEdit)
_GUICtrlMenu_InsertMenuItem ($hMain, 2, "&Help", 0, $hHelp)
; Set window menu
_GUICtrlMenu_SetMenu ($hGUI, $hMain)
GUISetState()
; Loop until user exits
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
EndFunc ;==>_Main
[ 本帖最后由 sd007 于 2009-3-24 16:22 编辑 ] 你若是要编译为exe文件,可以在头部加#AutoIt3Wrapper_UseAnsi=y
若在au3脚本中运行的话,可以改为_GUICtrlMenu_InsertMenuItem ($hFile, 0, "中文中文中文[这里有6个空格]", $idNew),或者修改_GUICtrlMenu_InsertMenuItem()函数如下:Func _GUICtrlMenu_InsertMenuItem($hMenu, $iIndex, $sText, $iCmdID = 0, $hSubMenu = 0)
Local $pMenu, $tMenu, $tText, $aResult
$tMenu = DllStructCreate($tagMENUITEMINFO)
$pMenu = DllStructGetPtr($tMenu)
DllStructSetData($tMenu, "Size", DllStructGetSize($tMenu))
DllStructSetData($tMenu, "Mask", BitOR($MIIM_ID, $MIIM_STRING, $MIIM_SUBMENU))
DllStructSetData($tMenu, "ID", $iCmdID)
DllStructSetData($tMenu, "SubMenu", $hSubMenu)
If $sText = "" Then
DllStructSetData($tMenu, "Mask", $MIIM_FTYPE)
DllStructSetData($tMenu, "Type", $MFT_SEPARATOR)
Else
DllStructSetData($tMenu, "Mask", BitOR($MIIM_ID, $MIIM_STRING, $MIIM_SUBMENU))
If StringIsASCII($sText) Then
$tText = DllStructCreate("char Text[" & StringLen($sText) + 1 & "]")
Else
$tText = DllStructCreate("wchar Text[" & StringLen($sText) * 2 & "]")
EndIf
DllStructSetData($tText, "Text", $sText)
DllStructSetData($tMenu, "TypeData", DllStructGetPtr($tText))
EndIf
If StringIsASCII($sText) Then
$aResult = DllCall("User32.dll", "int", "InsertMenuItem", "hwnd", $hMenu, "int", $iIndex, "int", True, "ptr", $pMenu)
Else
$aResult = DllCall("User32.dll", "int", "InsertMenuItemW", "hwnd", $hMenu, "int", $iIndex, "int", True, "ptr", $pMenu)
EndIf
;$aResult = DllCall("User32.dll", "int", "InsertMenuItem", "hwnd", $hMenu, "int", $iIndex, "int", True, "ptr", $pMenu)
Return $aResult <> 0
EndFunc ;==>_GUICtrlMenu_InsertMenuItem
[ 本帖最后由 pusofalse 于 2009-3-24 16:12 编辑 ] 谢谢 pusofalse ,我选用“修改_GUICtrlMenu_InsertMenuItem()"的办法 au3中文显示问题都是没加空格惹的祸 学习了一下。。 学习了,我也碰到这个问题了 很好学习了
页:
[1]