炫彩界面库AU3教程9,XRichEdit富文本框右键菜单的实现
请看代码#region ;**** 参数创建于 ACNWrapper_GUI ****#AutoIt3Wrapper_UseUpx=n
#AutoIt3Wrapper_UseX64=n
#endregion ;**** 参数创建于 ACNWrapper_GUI ****
#include "XCGUI_Fun.au3"
XInitXCGUI()
$create = XWnd_Create("500", "500", "380", "240", "窗口测试", 47)
$XRichEdit = XRichEdit_Create("20", "40", "120", "25", $create)
$btn2 = XBtn_Create("180", "40", "75", "25", "退出程序", $create)
XEle_RegEventC($btn2, "btn2")
XEle_RegEventC($XRichEdit, "XRichEdit_menu", $XE_RBUTTONUP, "int;int") ;注册鼠标右键弹起事件
XWnd_RegEventC($create, "_menuevent", $XWM_MENU_SELECT) ;注册菜单选择事件
XWnd_ShowWindow($create)
XRunXCGUI()
While 1
Sleep(50)
WEnd
Func btn2($bh)
xquit_acn($create)
EndFunc ;==>btn2
Func XRichEdit_menu($nFlags, $pPt)
Local $n, $m
$a = _POINT()
CopyMemory($a, $pPt)
$hMenu = XMenu_Create() ;创建菜单.默认弹出菜单窗口关闭后自动销毁
XMenu_AddItem($hMenu, 980201, "撤销(U)", $XC_ID_ROOT, 0) ;添加菜单项
XMenu_SetItemFlags($hMenu, 980201, $menu_item_flags_disable)
XMenu_AddItem($hMenu, 0, "", $XC_ID_ROOT, $menu_item_flags_separator)
XMenu_AddItem($hMenu, $IDM_CLIP, "剪切(T)", $XC_ID_ROOT, 0)
XMenu_AddItem($hMenu, $IDM_COPY, "复制(C)", $XC_ID_ROOT, 0)
XMenu_AddItem($hMenu, $IDM_PASTE, "粘贴(V)", $XC_ID_ROOT, 0)
XMenu_AddItem($hMenu, $IDM_DELETE, "删除(D)", $XC_ID_ROOT, 0)
XMenu_AddItem($hMenu, 0, "", $XC_ID_ROOT, $menu_item_flags_separator)
XMenu_AddItem($hMenu, $IDM_SELECTALL, "全选(A)", $XC_ID_ROOT, 0)
XEle_PointClientToWndClient($XRichEdit, DllStructGetPtr($a)) ;元素客户区坐标转换到窗口客户区坐标
ClientToScreen($create, $a) ;判断窗口内以客户区坐标表示的一个点的屏幕坐标非零表示成功,零表示失败
;弹出菜单
XMenu_Popup($hMenu, XWnd_GetHWND($create), DllStructGetData($a, "x"), DllStructGetData($a, "y"), 0, $menu_popup_position_left_top)
EndFunc ;==>XRichEdit_menu
Func _menuevent($nID)
Switch $nID
Case 980201
;撤销功能用处不大,所以没写
Case $IDM_SELECTALL ;全选
XRichEdit_SelectAll($XRichEdit)
XWnd_RedrawWnd($create, True)
Case $IDM_CLIP ;剪切
XRichEdit_ClipboardCut($XRichEdit)
XWnd_RedrawWnd($create, True)
Case $IDM_COPY ;复制
XRichEdit_ClipboardCopy($XRichEdit)
Case $IDM_PASTE ;粘贴
XRichEdit_ClipboardPaste($XRichEdit)
XWnd_RedrawWnd($create, True)
Case $IDM_DELETE ;删除
XRichEdit_DeleteSelect($XRichEdit)
XWnd_RedrawWnd($create, True)
EndSwitch
EndFunc ;==>_menuevent
回复 1# guland
"F:\炫彩界面库\炫彩UDF2.0\XRichEdit富文本框右键菜单.au3"(11,70) : 错误: XEle_RegEventC() 调用参数数量不正确.
XEle_RegEventC($XRichEdit, "XRichEdit_menu", $XE_RBUTTONUP, "int;int") 回复 2# chzj589
更新一下UDF 回复 3# guland
"F:\炫彩界面库\炫彩UDF2.0\XRichEdit富文本框右键菜单.au3"(23,21) : 错误: _POINT(): 未定义函数 回复 4# chzj589
现在最新的UDF版本是2.22 ,用炫彩助手中那个下载器更新 回复 5# guland
$a = _POINT()
这个是什么 回复 6# chzj589
返回一个POINT数据结构 回复 5# guland
好了,通过了。谢谢 回复 7# guland
两个以上的富文本编辑框,右键菜单代码如何写? 回复 7# guland
我这样写,但粘贴时,两个一起显示
Func XRichEdit_menub($nFlags, $pPt)
Local $n, $m
$b = _POINT()
CopyMemory($b, $pPt)
$hMenu1 = XMenu_Create() ;创建菜单.默认弹出菜单窗口关闭后自动销毁
XMenu_AddItem($hMenu1, 980201, "撤销(U)", $XC_ID_ROOT, 0) ;添加菜单项
XMenu_SetItemFlags($hMenu1, 980201, $menu_item_flags_disable)
XMenu_AddItem($hMenu1, 0, "", $XC_ID_ROOT, $menu_item_flags_separator)
XMenu_AddItem($hMenu1, $IDM_CLIP, "剪切(T)", $XC_ID_ROOT, 0)
XMenu_AddItem($hMenu1, $IDM_COPY, "复制(C)", $XC_ID_ROOT, 0)
XMenu_AddItem($hMenu1, $IDM_PASTE, "粘贴(V)", $XC_ID_ROOT, 0)
; XMenu_AddItem($hMenu1, $IDM_DELETE, "删除(D)", $XC_ID_ROOT, 0)
;XMenu_AddItem($hMenu1, 0, "", $XC_ID_ROOT, $menu_item_flags_separator)
;XMenu_AddItem($hMenu1, $IDM_SELECTALL, "全选(A)", $XC_ID_ROOT, 0)
XEle_PointClientToWndClient($XRichEditx1, DllStructGetPtr($b)) ;元素客户区坐标转换到窗口客户区坐标
ClientToScreen($create, $b) ;判断窗口内以客户区坐标表示的一个点的屏幕坐标非零表示成功,零表示失败
;弹出菜单
XMenu_Popup($hMenu1, XWnd_GetHWND($create), DllStructGetData($b, "x"), DllStructGetData($b, "y"), 0, $menu_popup_position_left_top)
EndFunc ;==>XRichEdit_menu
Func _menueventb($nIDb)
Switch $nIDb
;Case 980201
;撤销功能用处不大,所以没写
;Case $IDM_SELECTALL ;全选
;XRichEdit_SelectAll($XRichEditx1)
;XWnd_RedrawWnd($create, True)
; Case $IDM_CLIP ;剪切
;XRichEdit_ClipboardCut($XRichEditx1)
;XWnd_RedrawWnd($create, True)
Case $IDM_COPY ;复制
XRichEdit_ClipboardCopy($XRichEditx1)
;XWnd_RedrawWnd($create, True)
Case $IDM_PASTE ;粘贴
XRichEdit_ClipboardPaste($XRichEditx1)
XRichEdit_SetText($XRichEditx, "")
XWnd_RedrawWnd($create, True)
;Case $IDM_DELETE ;删除
;XRichEdit_DeleteSelect($XRichEditx1)
;XWnd_RedrawWnd($create, True)
EndSwitch
EndFunc ;==>_menuevent 回复 10# chzj589 #region ;**** 参数创建于 ACNWrapper_GUI ****
#AutoIt3Wrapper_UseUpx=n
#AutoIt3Wrapper_UseX64=n
#endregion ;**** 参数创建于 ACNWrapper_GUI ****
#include "XCGUI_Fun.au3"
Global $RichHwnd ;定义富文本框句柄全局变量
XInitXCGUI()
$create = XWnd_Create("500", "500", "380", "240", "窗口测试", 47)
$XRichEdit = XRichEdit_Create("20", "40", "120", "25", $create)
$XRichEdit1 = XRichEdit_Create("20", "100", "120", "25", $create)
$btn2 = XBtn_Create("180", "40", "75", "25", "退出程序", $create)
XEle_RegEventC($btn2, "btn2")
XEle_RegEventC($XRichEdit, "XRichEdit_menu", $XE_RBUTTONUP, "int;int") ;注册鼠标右键弹起事件
XEle_RegEventC($XRichEdit1, "XRichEdit_menu", $XE_RBUTTONUP, "int;int")
XWnd_RegEventC($create, "_menuevent", $XWM_MENU_SELECT) ;注册菜单选择事件
XWnd_ShowWindow($create)
XRunXCGUI()
While 1
Sleep(50)
WEnd
Func btn2($bh)
xquit_acn($create)
EndFunc ;==>btn2
Func XRichEdit_menu($nFlags, $pPt)
Local $n, $m
$a = _POINT()
CopyMemory($a, $pPt)
$RichHwnd = XWnd_GetStayHELE($create) ;获取当前鼠标所停留元素
$hMenu = XMenu_Create() ;创建菜单.默认弹出菜单窗口关闭后自动销毁
XMenu_AddItem($hMenu, 980201, "撤销(U)", $XC_ID_ROOT, 0) ;添加菜单项
XMenu_SetItemFlags($hMenu, 980201, $menu_item_flags_disable)
XMenu_AddItem($hMenu, 0, "", $XC_ID_ROOT, $menu_item_flags_separator)
XMenu_AddItem($hMenu, $IDM_CLIP, "剪切(T)", $XC_ID_ROOT, 0)
XMenu_AddItem($hMenu, $IDM_COPY, "复制(C)", $XC_ID_ROOT, 0)
XMenu_AddItem($hMenu, $IDM_PASTE, "粘贴(V)", $XC_ID_ROOT, 0)
XMenu_AddItem($hMenu, $IDM_DELETE, "删除(D)", $XC_ID_ROOT, 0)
XMenu_AddItem($hMenu, 0, "", $XC_ID_ROOT, $menu_item_flags_separator)
XMenu_AddItem($hMenu, $IDM_SELECTALL, "全选(A)", $XC_ID_ROOT, 0)
XEle_PointClientToWndClient($RichHwnd, DllStructGetPtr($a)) ;元素客户区坐标转换到窗口客户区坐标
ClientToScreen($create, $a) ;判断窗口内以客户区坐标表示的一个点的屏幕坐标非零表示成功,零表示失败
;弹出菜单
XMenu_Popup($hMenu, XWnd_GetHWND($create), DllStructGetData($a, "x"), DllStructGetData($a, "y"), 0, $menu_popup_position_left_top)
EndFunc ;==>XRichEdit_menu
Func _menuevent($nID)
Switch $nID
Case 980201
;撤销功能用处不大,所以没写
Case $IDM_SELECTALL ;全选
XRichEdit_SelectAll($RichHwnd) ;使用富文本框句柄全局变量
XWnd_RedrawWnd($create, True)
Case $IDM_CLIP ;剪切
XRichEdit_ClipboardCut($RichHwnd)
XWnd_RedrawWnd($create, True)
Case $IDM_COPY ;复制
XRichEdit_ClipboardCopy($RichHwnd)
Case $IDM_PASTE ;粘贴
XRichEdit_ClipboardPaste($RichHwnd)
XWnd_RedrawWnd($create, True)
Case $IDM_DELETE ;删除
XRichEdit_DeleteSelect($RichHwnd)
XWnd_RedrawWnd($create, True)
EndSwitch
EndFunc ;==>_menuevent
回复 11# guland
谢谢!{:face (361):} 本帖最后由 chzj589 于 2016-4-19 15:11 编辑
回复 11# guland
有个小小问题,两个富文本框不能相互复制与粘贴
加上:XRichEdit_EnableAutoWrap($XRichEdit, True);启用自动换行
两个富文本框不能相互复制与粘贴 回复 13# chzj589
新版的DLL没有这个问题,我用内侧版已经测试过了,很快就会发布正式版 回复 14# guland
期待中------{:face (72):}
页:
[1]
2