#include <GuiRichEdit.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiMenu.au3>
Global $hRichEdit, $mnu, $mnuUndo, $mnuRedo, $mnuCut, $mnuCopy
Global $mnuPaste, $mnuPasteSpl, $mnuPasteSplRTF, $mnuPasteSplwObjs
$Form2 = GUICreate("窗体1", 342, 197, 353, 251)
$Tab1 = GUICtrlCreateTab(0, 0, 337, 193)
$TabSheet1 = GUICtrlCreateTabItem("TabSheet1")
$Button1 = GUICtrlCreateButton("Button1", 24, 40, 75, 25)
$TabSheet2 = GUICtrlCreateTabItem("TabSheet2")
GUICtrlSetState(-1,$GUI_SHOW)
$hRichEdit = _GUICtrlRichEdit_Create($Form2, "This is a test.", 8, 32, 321, 137)
;$hRichEdit = GUICtrlCreateEdit("", 8, 32, 321, 137)
;GUICtrlSetData(-1, "Edit1")
GUICtrlCreateTabItem("")
GUISetState(@SW_SHOW)
;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 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
GUIDelete()
Exit
Case $TabSheet1
MsgBox(64,'提示','提示')
EndSwitch
WEnd
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($tagEN_MSGFILTER, $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