GUICtrlCreateEdit创建的Edit控件中怎样添加右键菜单(已解决)
本帖最后由 lsszmj 于 2012-6-12 18:07 编辑Global $gu_Edit1 = GUICtrlCreateEdit("", 5, 238, 320, 125,$WS_VSCROLL + $ES_WANTRETURN)
Global $gu_MenuItem1 = GUICtrlCreateContextMenu($gu_Edit1 )
Global $gu_MenuItem2 = GUICtrlCreateMenuItem("右键菜单", $gu_MenuItem1)右键菜单不显示?是怎么回事?谢谢各位支个招哈! 回复 1# lsszmj
论坛上有.
这是我以前收藏的. 原来是左键菜单,现在改成右键了.
#include <GuiConstants.au3>
$Gui = GUICreate("test")
$Edit = GUICtrlCreateEdit("", 20, 20)
$DummyMenu = GUICtrlCreateDummy()
$ContextMenu = GUICtrlCreateContextMenu($DummyMenu)
$MenuItem1 = GUICtrlCreateMenuItem("菜单1", $ContextMenu)
$MenuItem2 = GUICtrlCreateMenuItem("菜单2", $ContextMenu)
GUICtrlCreateMenuItem("", $ContextMenu)
$ExitMenuItem = GUICtrlCreateMenuItem("退出", $ContextMenu)
GUISetState()
While 1
$CurInfo = GUIGetCursorInfo($Gui)
$Msg = GUIGetMsg()
Select
Case $Msg = -3
Exit
Case $CurInfo = 1 And $CurInfo = $Edit
ShowMenu($Gui, $ContextMenu)
Case $msg = $ExitMenuItem
Exit
EndSelect
WEnd
; Show a menu in a given GUI window which belongs to a given GUI ctrl
Func ShowMenu($hWnd, $nContextID)
Local $hMenu = GUICtrlGetHandle($nContextID)
$arPos = MouseGetPos()
Local $x = $arPos
Local $y = $arPos
DllCall("user32.dll", "int", "TrackPopupMenuEx", "hwnd", $hMenu, "int", 0, "int", $x, "int", $y, "hwnd", $hWnd, "ptr", 0)
EndFunc
Func _exit()
Exit
EndFunc
左键菜单:Case $CurInfo = 1 And $CurInfo = $Edit
ShowMenu($Gui, $ContextMenu) 要善用论坛搜索:
http://www.autoitx.com/search.php?searchid=296&orderby=lastpost&ascdesc=desc&searchsubmit=yes
页:
[1]