官方富文本控件管理GUIRichEdit示例中的右键菜单咋运行不起
如题,上代码,期待各位大神支招,谢谢#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
XP测试右键菜单未见异常 最前面缺少:#AutoIt3Wrapper_UseX64=n
afan 发表于 2020-5-31 16:16
XP测试右键菜单未见异常
谢谢A大,win10测试运行不起来 chzj589 发表于 2020-5-31 18:43
最前面缺少:#AutoIt3Wrapper_UseX64=n
实测,WIN10成功运行,谢谢 afan 发表于 2020-5-31 16:16
XP测试右键菜单未见异常
:face (17):还在用XP????? 破帽遮颜 发表于 2020-6-1 19:42
还在用XP?????
肿麽?不服气?简单粗暴耐操就是王道。 afan 发表于 2020-6-1 19:44
肿麽?不服气?简单粗暴耐操就是王道。
XP系统兼容性好,怀念。因旧笔记本报废,换一台不能装XP系统,只能用WIN7 chzj589 发表于 2020-6-1 21:22
XP系统兼容性好,怀念。因旧笔记本报废,换一台不能装XP系统,只能用WIN7
主要诟病于XP以上平台的资源管理器,不然也早就跟进了。
不过辅助工具也写了一些,差不多了,以后直接上Win10+辅助就ok了~
页:
[1]