函数参考


_GUICtrlRichEdit_GetCharWordBreakInfo

获取上一个单词之前的字符区间位置

#Include <GuiRichEdit.au3>
_GUICtrlRichEdit_GetCharWordBreakInfo($hWnd, $iCp)

参数

$hWnd 控件句柄
$iCP 上一个字符的字符区间位置

返回值

成功: 返回用逗号分隔的字符串值:
值 1 - 字的断开标志:
c - 该字符后的行可能会被打断
d - 字符是结尾词定界符.行可能定界符后被打断
w - 字符是空白. (空白区不包含在行长度中.)
值 2 - 字符类别:一个数
失败: 返回 "" ,设置@error:
@error: 101 - $hWnd 参数值不是句柄
102 - $iCp 不是一个数字

注意/说明

 行可能会打断或分隔不同类之间的字符.
 在文字中断程序中定义字符类别.
 程序中的默认类是:
 0 = 文字数字式字符, 1 = 其它印刷字符 (除了连字符),
 2 = 空格, 3 = 制表符, 4 = 连字符或段落结束.

相关

_GUICtrlRichEdit_GetCharPosOfNextWord, _GUICtrlRichEdit_GetCharPosOfPreviousWord

详情参考

在MSDN中搜索


示例/演示


#include <GuiRichEdit.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Global $lblMsg, $hRichEdit

Main()

Func Main()
    Local $hGui, $iMsg, $btnNext, $iCp = -1, $s
    $hGui = GUICreate("Example (" & StringTrimRight(@ScriptName, 4) & ")", 320, 350, -1, -1)
    $hRichEdit = _GUICtrlRichEdit_Create($hGui, "This is a test.", 10, 10, 300, 220, _
            BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL))
    $lblMsg = GUICtrlCreateLabel("", 10, 235, 300, 60)
    $btnNext = GUICtrlCreateButton("Next", 270, 310, 40, 30)
    GUISetState()

    $s = Chr(9)
    For $i = 32 To 126
        $s &= Chr($i)
    Next
    _GUICtrlRichEdit_AppendText($hRichEdit, $s & @CR)
    _GUICtrlRichEdit_AppendText($hRichEdit, "AutoIt v3 is a (freeware) BASIC-like scripting language designed for " _
             & "automating the Windows GUI and general scripting.")
    _GUICtrlRichEdit_AppendText($hRichEdit, @CRLF & "Another paragraph")
    While True
        $iMsg = GUIGetMsg()
        Select
            Case $iMsg = $GUI_EVENT_CLOSE
                _GUICtrlRichEdit_Destroy($hRichEdit) ; 除非脚本崩溃才需要
;~              GUIDelete()     ; 同样行
                Exit
            Case $iMsg = $btnNext
                $iCp += 1
                _GUICtrlRichEdit_GotoCharPos($hRichEdit, $iCp)
                GUICtrlSetData($lblMsg, _GUICtrlRichEdit_GetCharWordBreakInfo($hRichEdit, $iCp))
                ControlFocus($hRichEdit, "", "")
        EndSelect
    WEnd
EndFunc   ;==>Main

Func Report($sMsg)
    GUICtrlSetData($lblMsg, $sMsg)
EndFunc   ;==>Report

Func GetWord($hWnd, $iCp, $fForward, $fStartOfWord, $fClass = False)
    Local $iRet, $iWparam
    If $fClass Then
        If $fForward Then
            $iWparam = $WB_MOVEWORDRIGHT
        Else
            $iWparam = $WB_MOVEWORDLEFT
        EndIf
    Else
        If $fForward Then
            If $fStartOfWord Then
                $iWparam = $WB_RIGHT
            Else
                $iWparam = $WB_LEFT
            EndIf
        Else
            If $fStartOfWord Then
                $iWparam = $WB_RIGHTBREAK
            Else
                $iWparam = $wb_LEFTBREAK
            EndIf
        EndIf
    EndIf
    $iRet = _SendMessage($hWnd, $EM_FINDWORDBREAK, $iWparam, $iCp)
    ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $iWparam = ' & $iWparam & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
    Return $iRet
EndFunc   ;==>GetWord