Function Reference


_GUICtrlRichEdit_SetEventMask

Specifies which notification messages are sent to the parent window

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

Parameters

$hWnd Handle to the control
$iEventMask BitOR combination of :
    $ENM_CHANGE - Sends $EN_CHANGE notifications (user may have altered text)
    $ENM_CORRECTTEXT - Sends $EN_CORRECTTEXT notifications (parent window can cancel correction of text)
    $ENM_DRAGDROPDONE - Sends $EN_DRAGDROPDONE notifications (drag and drop operation completed)
    $ENM_DROPFILES - Sends $EN_DROPFILES notifications (user is attempting to drop files into the control)
    $ENM_KEYEVENTS - Sends $EN_MSGFILTER notifications for keyboard events
    $ENM_LINK - Sends $EN_LINK notifications when the mouse pointer is over text having the link character attribute set and when user clicks the mouse [2.0+]
    $ENM_MOUSEEVENTS - Sends $EN_MSGFILTER notifications for mouse events to parent window
    $ENM_OBJECTPOSITIONS - Sends $EN_OBJECTPOSITIONS notifications when the control reads in objects
    $ENM_PROTECTED - Sends $EN_PROTECTED notifications when the user attempts to change characters having the protected attribute set
    $ENM_REQUESTRESIZE - Sends $EN_REQUESTRESIZE notifications that the control's contents are either smaller or larger than the control's window size
    $ENM_SCROLL - Sends $EN_HSCROLL and $EN_VSCROLL notifications when the user clicks the horizontal/vertical scroll bar
    $ENM_SCROLLEVENTS - Sends EN_MSGFILTER notifications for mouse wheel events
    $ENM_SELCHANGE - Sends EN_SELCHANGE notifications when the current selection changes
    $ENM_UPDATE - Sends EN_UPDATE notifications when a control is about to redraw itself
or
    $ENM_NONE - Disables sending of notification messages to the parent window

Return Value

Success: True.
Failure: False and sets the @error flag to non-zero.
@error: 101 - $hWnd is not a handle
102 - $iEventMask is not a number

Remarks

The number in parentheses indicate which versions mask settings apply to.

$ENM_IMECHANGE only applies to Asian-language versions of Windows.

$EN_UPDATE notifications are always sent except for when 4.0 is emulating 1.0

Related

_GUICtrlRichEdit_AutoDetectURL

See Also

Search EM_SETEVENTMASK in MSDN Library.

Example

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

Global $g_hRichEdit, $g_idMnu, $g_idMnuUndo, $g_idMnuRedo, $g_idMnuCut, $g_idMnuCopy
Global $g_idMnuPaste, $g_idMnuPasteSpl

Example()

Func Example()
    Local $hGui, $idMnuPasteSplRTF, $idMnuPasteSplwObjs
    $hGui = GUICreate("Example (" & StringTrimRight(@ScriptName, StringLen(".exe")) & ")", 320, 350, -1, -1)
    $g_hRichEdit = _GUICtrlRichEdit_Create($hGui, "This is a test.", 10, 10, 300, 220, _
            BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL))
    GUISetState(@SW_SHOW)

    _GUICtrlRichEdit_AppendText($g_hRichEdit, ReadBmpToRtf(FindFirstBMP()))

    GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

    $g_idMnu = GUICtrlCreateContextMenu(GUICtrlCreateDummy())
    $g_idMnuUndo = GUICtrlCreateMenuItem("Undo", $g_idMnu)
    $g_idMnuRedo = GUICtrlCreateMenuItem("Redo", $g_idMnu)
    GUICtrlCreateMenuItem("", $g_idMnu)
    $g_idMnuCut = GUICtrlCreateMenuItem("Cut", $g_idMnu)
    $g_idMnuCopy = GUICtrlCreateMenuItem("Copy", $g_idMnu)
    $g_idMnuPaste = GUICtrlCreateMenuItem("Paste", $g_idMnu)
    $g_idMnuPasteSpl = GUICtrlCreateMenu("Paste Special", $g_idMnu)
    $idMnuPasteSplRTF = GUICtrlCreateMenuItem("RTF only", $g_idMnuPasteSpl)
    $idMnuPasteSplwObjs = GUICtrlCreateMenuItem("With objects", $g_idMnuPasteSpl)
    _GUICtrlRichEdit_SetEventMask($g_hRichEdit, $ENM_MOUSEEVENTS)

    While True
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                _GUICtrlRichEdit_Destroy($g_hRichEdit) ; needed unless script crashes
                ; GUIDelete()   ; is OK too
                Exit
            Case $g_idMnuUndo
                _GUICtrlRichEdit_Undo($g_hRichEdit)
            Case $g_idMnuRedo
                _GUICtrlRichEdit_Redo($g_hRichEdit)
            Case $g_idMnuCut
                _GUICtrlRichEdit_Cut($g_hRichEdit)
            Case $g_idMnuCopy
                _GUICtrlRichEdit_Copy($g_hRichEdit)
            Case $g_idMnuPaste
                _GUICtrlRichEdit_Paste($g_hRichEdit)
            Case $idMnuPasteSplRTF
                _GUICtrlRichEdit_PasteSpecial($g_hRichEdit, False)
            Case $idMnuPasteSplwObjs
                _GUICtrlRichEdit_PasteSpecial($g_hRichEdit, True)
        EndSwitch
    WEnd
EndFunc   ;==>Example

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

Func SetMenuTexts($hWnd, $hMenu)
    Local $bState
    If _GUICtrlRichEdit_CanUndo($hWnd) Then
        _GUICtrlMenu_SetItemEnabled($hMenu, $g_idMnuUndo, True, False)
        _GUICtrlMenu_SetItemText($hMenu, $g_idMnuUndo, "Undo: " & _GUICtrlRichEdit_GetNextUndo($hWnd), False)
    Else
        _GUICtrlMenu_SetItemText($hMenu, $g_idMnuUndo, "Undo", False)
        _GUICtrlMenu_SetItemEnabled($hMenu, $g_idMnuUndo, False, False)
    EndIf
    If _GUICtrlRichEdit_CanRedo($hWnd) Then
        _GUICtrlMenu_SetItemEnabled($hMenu, $g_idMnuRedo, True, False)
        _GUICtrlMenu_SetItemText($hMenu, $g_idMnuRedo, "Redo: " & _GUICtrlRichEdit_GetNextRedo($hWnd), False)
    Else
        _GUICtrlMenu_SetItemText($hMenu, $g_idMnuRedo, "Redo", False)
        _GUICtrlMenu_SetItemEnabled($hMenu, $g_idMnuRedo, False, False)
    EndIf
    $bState = _GUICtrlRichEdit_IsTextSelected($hWnd)
    _GUICtrlMenu_SetItemEnabled($hMenu, $g_idMnuCut, $bState, False)
    _GUICtrlMenu_SetItemEnabled($hMenu, $g_idMnuCopy, $bState, False)

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

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

Func ReadBmpToRtf($sBmpFilspc)
    Local $hFile, $sRtf
    $hFile = FileOpen($sBmpFilspc, $FO_BINARY)
    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 = Default)
    If $sPath = Default Then
        ; X64 running support
        Local $sWow64 = ""
        If @AutoItX64 Then $sWow64 = "\Wow6432Node"

        $sPath = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE" & $sWow64 & "\AutoIt v3\AutoIt", "InstallDir") & "\Examples\GUI\Advanced\Images"
    EndIf
    Local $hFind, $sBmpFilspc
    $hFind = FileFindFirstFile($sPath & "\*.bmp")
    $sBmpFilspc = FileFindNextFile($hFind)
    FileClose($hFind)
    Return $sPath & "\" & $sBmpFilspc
EndFunc   ;==>FindFirstBMP