函数参考


_GUICtrlRichEdit_SetEventMask

发送通知消息到指定的父窗口

#Include <GuiRichEdit.au3>
_GUICtrlRichEdit_SetEventMask($hWnd, $iEventMask)

参数

$hWnd 控件句柄
$iEventMask BitOr 组合 :
$ENM_CHANGE - 发送 $EN_CHANGE 通知
(用户可能已经改变了文本)
$ENM_CORRECTTEXT - 发送 $EN_CORRECTTEXT 通知
(父窗口可以取消文字修正)
$ENM_DRAGDROPDONE - 发送 $EN_DRAGDROPDONE 通知
(拖放操作完成)
$ENM_DROPFILES - 发送 $EN_DROPFILES 通知
(用户试图拖放文件夹到控件)
$ENM_KEYEVENTS - 发送 $EN_MSGFILTER 通知
(为键盘事件)
$ENM_LINK - 发送 $EN_LINK 通知
(当鼠标指针指向有链接属性的文字,且用户点击了该字符)[2.0+]
$ENM_MOUSEEVENTS - 发送 $EN_MSGFILTER 通知
(为父窗口的鼠标事件)
$ENM_OBJECTPOSITIONS - 发送 $EN_OBJECTPOSITIONS 通知
(当控件读取对象时)
$ENM_PROTECTED - 发送 $EN_PROTECTED 通知
(当用户试图更改有保护属性的字符集时)
$ENM_REQUESTRESIZE - 发送 $EN_REQUESTRESIZE 通知
(当控件内容小于或大于控件的窗口大小时)
$ENM_SCROLL - 发送 $EN_HSCROLL and $EN_VSCROLL 通知
(当用户点击水平/垂直滚动条时)
$ENM_SCROLLEVENTS - 发送 EN_MSGFILTER 通知
(为鼠标滚轮事件)
$ENM_SELCHANGE - 发送 EN_SELCHANGE 通知
(当前选择发送变化时)
$ENM_UPDATE - 发送 EN_UPDATE 通知
(当一个控件即将刷新自身时)

$ENM_NONE - 禁用发送通知消息到父窗口

返回值

成功: 返回 True
失败: 返回 False设置@error
@error: 101 - $hWnd 参数值不是句柄
102 - $iEventMask 不是一个数字

注意/说明

 括号中的数字表明适用设置的版本号.
 $ENM_IMECHANGE 仅适用于 Windows 的亚洲语言版本
 $EN_UPDATE 总是发送通知,除了 4.0 模仿 1.0

相关

_GUICtrlRichEdit_AutoDetectURL

详情参考

在MSDN中搜索


示例/演示


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

Global $hRichEdit, $mnu, $mnuUndo, $mnuRedo, $mnuCut, $mnuCopy
Global $mnuPaste, $mnuPasteSpl, $mnuPasteSplRTF, $mnuPasteSplwObjs

Main()

Func Main()
    Local $hGui
    $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))
    GUISetState(@SW_SHOW)

    _GUICtrlRichEdit_AppendText($hRichEdit, ReadBmpToRtf(FindFirstBMP()) & @CR)

    GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

    $mnu = GUICtrlCreateContextMenu(GUICtrlCreateDummy())
    $mnuUndo = GUICtrlCreateMenuItem("Undo", $mnu)
    $mnuRedo = GUICtrlCreateMenuItem("Redo", $mnu)
    GUICtrlCreateMenuItem("", $mnu)
    $mnuCut = GUICtrlCreateMenuItem("Cut", $mnu)
    $mnuCopy = GUICtrlCreateMenuItem("Copy", $mnu)
    $mnuPaste = GUICtrlCreateMenuItem("Paste", $mnu)
    $mnuPasteSpl = GUICtrlCreateMenu("Paste Special", $mnu)
    $mnuPasteSplRTF = GUICtrlCreateMenuItem("RTF only", $mnuPasteSpl)
    $mnuPasteSplwObjs = GUICtrlCreateMenuItem("With objects", $mnuPasteSpl)
    _GUICtrlRichEdit_SetEventMask($hRichEdit, $ENM_MOUSEEVENTS)

    While True
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                _GUICtrlRichEdit_Destroy($hRichEdit) ; 除非脚本崩溃才需要
;~              GUIDelete()     ; 同样行
                Exit
            Case $mnuUndo
                _GUICtrlRichEdit_Undo($hRichEdit)
            Case $mnuRedo
                _GUICtrlRichEdit_Redo($hRichEdit)
            Case $mnuCut
                _GUICtrlRichEdit_Cut($hRichEdit)
            Case $mnuCopy
                _GUICtrlRichEdit_Copy($hRichEdit)
            Case $mnuPaste
                _GUICtrlRichEdit_Paste($hRichEdit)
            Case $mnuPasteSplRTF
                _GUICtrlRichEdit_PasteSpecial($hRichEdit, False)
            Case $mnuPasteSplwObjs
                _GUICtrlRichEdit_PasteSpecial($hRichEdit, True)
        EndSwitch
    WEnd
EndFunc   ;==>Main

Func WM_NOTIFY($hWnd, $iMsg, $iWparam, $iLparam)
    #forceref $iMsg, $iWparam
    Local $hWndFrom, $iCode, $tNMHDR, $tMsgFilter, $hMenu
    $tNMHDR = DllStructCreate($tagNMHDR, $iLparam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $hRichEdit
            Select
                Case $iCode = $EN_MSGFILTER
                    $tMsgFilter = DllStructCreate($tagMSGFILTER, $iLparam)
                    If DllStructGetData($tMsgFilter, "msg") = $WM_RBUTTONUP Then
                        $hMenu = GUICtrlGetHandle($mnu)
                        SetMenuTexts($hWndFrom, $hMenu)
                        _GUICtrlMenu_TrackPopupMenu($hMenu, $hWnd)
                    EndIf
            EndSelect
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

Func SetMenuTexts($hWnd, $hMenu)
    Local $fState
    If _GUICtrlRichEdit_CanUndo($hWnd) Then
        _GUICtrlMenu_SetItemEnabled($hMenu, $mnuUndo, True, False)
        _GUICtrlMenu_SetItemText($hMenu, $mnuUndo, "Undo: " & _GUICtrlRichEdit_GetNextUndo($hWnd), False)
    Else
        _GUICtrlMenu_SetItemText($hMenu, $mnuUndo, "Undo", False)
        _GUICtrlMenu_SetItemEnabled($hMenu, $mnuUndo, False, False)
    EndIf
    If _GUICtrlRichEdit_CanRedo($hWnd) Then
        _GUICtrlMenu_SetItemEnabled($hMenu, $mnuRedo, True, False)
        _GUICtrlMenu_SetItemText($hMenu, $mnuRedo, "Redo: " & _GUICtrlRichEdit_GetNextRedo($hWnd), False)
    Else
        _GUICtrlMenu_SetItemText($hMenu, $mnuRedo, "Redo", False)
        _GUICtrlMenu_SetItemEnabled($hMenu, $mnuRedo, False, False)
    EndIf
    $fState = _GUICtrlRichEdit_IsTextSelected($hWnd)
    _GUICtrlMenu_SetItemEnabled($hMenu, $mnuCut, $fState, False)
    _GUICtrlMenu_SetItemEnabled($hMenu, $mnuCopy, $fState, False)

    _GUICtrlMenu_SetItemEnabled($hMenu, $mnuPaste, _GUICtrlRichEdit_CanPaste($hWnd))

    _GUICtrlMenu_SetItemEnabled($hMenu, $mnuPasteSpl, _GUICtrlRichEdit_CanPasteSpecial($hWnd), False)
EndFunc   ;==>SetMenuTexts

Func ReadBmpToRtf($sBmpFilspc)
    Local $hFile, $sRtf
    $hFile = FileOpen($sBmpFilspc, 16)
    If FileRead($hFile, 2) <> "0x424D" Then Return SetError(1, 0, "")
    FileRead($hFile, 12)
    $sRtf = '{\rtf1{\pict\dibitmap ' & Hex(FileRead($hFile)) & '}}'
    FileClose($hFile)
    Return $sRtf
EndFunc   ;==>ReadBmpToRtf

Func FindFirstBMP($sPath = @WindowsDir)
    Local $hFind, $sBmpFilspc
    $hFind = FileFindFirstFile($sPath & "\*.bmp")
    $sBmpFilspc = FileFindNextFile($hFind)
    FileClose($hFind)
    Return $sPath & "\" & $sBmpFilspc
EndFunc   ;==>FindFirstBMP