找回密码
 加入
搜索
查看: 1831|回复: 2

[GUI管理] GUICtrlCreateEdit创建的Edit控件中怎样添加右键菜单(已解决)

[复制链接]
发表于 2012-6-9 09:42:55 | 显示全部楼层 |阅读模式
本帖最后由 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)
右键菜单不显示?是怎么回事?谢谢各位支个招哈!
发表于 2012-6-12 17:05:49 | 显示全部楼层
回复 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[3] = 1 And $CurInfo[4] = $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[0]
    Local $y = $arPos[1]
    DllCall("user32.dll", "int", "TrackPopupMenuEx", "hwnd", $hMenu, "int", 0, "int", $x, "int", $y, "hwnd", $hWnd, "ptr", 0)
EndFunc
Func _exit()
        Exit
EndFunc


左键菜单:
Case $CurInfo[2] = 1 And $CurInfo[4] = $Edit
            ShowMenu($Gui, $ContextMenu)
发表于 2012-6-12 17:12:45 | 显示全部楼层
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-11-22 07:45 , Processed in 0.099190 second(s), 23 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表