_GUICtrlEdit_ReplaceSel不支持中文
本帖最后由 sd007 于 2009-5-29 10:55 编辑_GUICtrlEdit_ReplaceSel不支持中文,请问怎么解决?#AutoIt3Wrapper_au3check_parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#include <GuiEdit.au3>
#include <GuiStatusBar.au3>
#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
Opt('MustDeclareVars', 1)
$Debug_Ed = False ; Check ClassName being passed to Edit functions, set to True and use a handle to another control to see it work
_Main()
Func _Main()
Local $StatusBar, $hEdit, $hGUI
Local $sFile = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\AutoIt v3\AutoIt", "InstallDir") & "\include\changelog.txt"
Local $aPartRightSide =
; Create GUI
$hGUI = GUICreate("Edit Replace Sel", 400, 300)
$hEdit = GUICtrlCreateEdit("", 2, 2, 394, 268, BitOR($ES_WANTRETURN, $WS_VSCROLL))
$StatusBar = _GUICtrlStatusBar_Create($hGUI, $aPartRightSide)
_GUICtrlStatusBar_SetIcon($StatusBar, 2, 97, "shell32.dll")
GUISetState()
; Set Margins
_GUICtrlEdit_SetMargins($hEdit, BitOR($EC_LEFTMARGIN, $EC_RIGHTMARGIN), 10, 10)
; Set Text
_GUICtrlEdit_SetText($hEdit, FileRead($sFile))
; Set Sel
_GUICtrlEdit_SetSel($hEdit, 0, 8)
MsgBox(4160, "Information", "Replace Sel")
_GUICtrlEdit_ReplaceSel($hEdit, "中国")
; Loop until user exits
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
GUIDelete()
EndFunc ;==>_Main "中国" 改为"中国 " 2个汉字用这种办法是可以的,但如果更多汉字或者汉字+英文就不好用了
我试着修改_GUICtrlEdit_ReplaceSel函数,但不成功,还是乱码
Func _GUICtrlEdit_ReplaceSel($hWnd, $sText, $fUndo = True)
If $Debug_Ed Then _GUICtrlEdit_ValidateClassName($hWnd)
If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
Local $struct_MemMap
If StringIsASCII($sText) Then
Local $struct_String = DllStructCreate("char Text[" & StringLen($sText) + 1 & "]")
Else
Local $struct_String = DllStructCreate("wchar Text[" & StringLen($sText) * 2 & "]")
EndIf
Local $sBuffer_pointer = DllStructGetPtr($struct_String)
DllStructSetData($struct_String, "Text", $sText)
;MsgBox(0,"",DllStructGetData($struct_String, "Text"));这里能取到正确的中文
If StringIsASCII($sText) Then
_MemInit($hWnd, StringLen($sText) + 1, $struct_MemMap)
Else
_MemInit($hWnd, StringLen($sText) * 2, $struct_MemMap)
EndIf
_MemWrite($struct_MemMap, $sBuffer_pointer)
_SendMessage($hWnd, $EM_REPLACESEL, $fUndo, $sBuffer_pointer, true, "wparam", "ptr")
_MemFree($struct_MemMap)
EndFunc ;==>_GUICtrlEdit_ReplaceSel 可以用 SendX("中华人民共和国")
Func SendX($string)
Local $clup
$clup = ClipGet()
ClipPut($string)
Send("+{ins}")
ClipPut($clup)
EndFunc ;==>SendX 本帖最后由 sensel 于 2009-5-29 10:15 编辑
StringLen惹的祸。你可以想办法弄出字符串中中文字符的个数,然后在字符串后加上等量的空格。 补空格代码:
Local $sString, $sCHN
$sString = "a0c中w*w文k/s字c符a"
$sCHN = StringRegExpReplace($sString, "[\x00-\xFF]", "")
For $i = 1 To StringLen($sCHN)
$sString &= " "
Next
MsgBox(0, "Length: " & StringLen($sCHN), '[' & $sString & ']') 解决了,谢谢pcbar 、sensel 看下楼主自己发的这个帖子,说不定有所启示。
http://www.autoitx.com/forum.php?mod=viewthread&tid=5966&highlight= 谢谢pusofalse, 我的记性太差了 Re sd007:#include <GUIEdit.au3>
#include <GUIConstants.au3>
$hGUI = GUICreate("", 400, 300)
$hEdit = _GUICtrlEdit_Create($hGUI, "", 5, 5, 390, 280)
GUISetState()
_GUICtrlEdit_SetText($hEdit, FileRead("test.txt"))
_GUICtrlEdit_SetSel($hEdit, 15, 20)
$sText = "中国"
_SendMessage($hEdit, $EM_REPLACESEL, 0, $sText, 0, "wparam", "str")
Do
Until guiGetMsg() = -3 到底是不是AU的问题? Re sd007:#include
#include
$hGUI = GUICreate("", 400, 300)
$hEdit = _GUICtrlEdit_Create($hGUI, "", 5, 5, 390, 280)
GUISetState()
_GUICtrlEdit_SetText($hEdit, FileRead("test.txt"))
_GUICt ...
pusofalse 发表于 2009-5-30 08:19 http://www.autoitx.com/images/common/back.gif
呵呵,还可以用这么简单的方法呀
页:
[1]