找回密码
 加入
搜索
查看: 1584|回复: 3

点击控件弹出菜单是如何写的?

[复制链接]
发表于 2009-7-25 21:46:06 | 显示全部楼层 |阅读模式
本帖最后由 l4ever 于 2009-7-25 23:07 编辑

我表述可能不是很清楚,所以抓图了

图上点击三角弹出一个新的菜单.

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
发表于 2009-7-25 21:48:06 | 显示全部楼层
帮助里有关于这种组合框的建立
发表于 2017-3-27 14:47:19 | 显示全部楼层
回复 1# l4ever


    #include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>

Local $hGui, $OptionsBtn, $OptionsDummy, $OptionsContext, $OptionsCommon, $OptionsFile, $msg
Local $OptionsExit, $HelpBtn, $HelpDummy, $HelpContext, $HelpWWW, $HelpAbout
$hGui = GUICreate("My GUI", 170, 40)

$OptionsBtn = GUICtrlCreateButton("&Options", 10, 10, 70, 20, $BS_FLAT)

; At first create a dummy control for the options and a contextmenu for it
$OptionsDummy = GUICtrlCreateDummy()
$OptionsContext = GUICtrlCreateContextMenu($OptionsDummy)
$OptionsCommon = GUICtrlCreateMenuItem("Common", $OptionsContext)
$OptionsFile = GUICtrlCreateMenuItem("File", $OptionsContext)
GUICtrlCreateMenuItem("", $OptionsContext)
$OptionsExit = GUICtrlCreateMenuItem("Exit", $OptionsContext)


$HelpBtn = GUICtrlCreateButton("&Help", 90, 10, 70, 20, $BS_FLAT)

; Create a dummy control and a contextmenu for the help too
$HelpDummy = GUICtrlCreateDummy()
$HelpContext = GUICtrlCreateContextMenu($HelpDummy)
$HelpWWW = GUICtrlCreateMenuItem("Website", $HelpContext)
GUICtrlCreateMenuItem("", $HelpContext)
$HelpAbout = GUICtrlCreateMenuItem("About...", $HelpContext)


GUISetState()

While 1
        $msg = GUIGetMsg()

        Switch $msg
                Case $OptionsExit, $GUI_EVENT_CLOSE
                        ExitLoop

                Case $OptionsBtn
                        ShowMenu($hGui, $msg, $OptionsContext)

                Case $HelpBtn
                        ShowMenu($hGui, $msg, $HelpContext)

                Case $HelpAbout
                        MsgBox(64, "About...", "GUICtrlGetHandle-Sample")
        EndSwitch
WEnd
GUIDelete()

; Show a menu in a given GUI window which belongs to a given GUI ctrl
Func ShowMenu($hWnd, $CtrlID, $nContextID)
        Local $arPos, $x, $y
        Local $hMenu = GUICtrlGetHandle($nContextID)

        $arPos = ControlGetPos($hWnd, "", $CtrlID)

        $x = $arPos[0]
        $y = $arPos[1] + $arPos[3]

        ClientToScreen($hWnd, $x, $y)
        TrackPopupMenu($hWnd, $hMenu, $x, $y)
EndFunc   ;==>ShowMenu


; Convert the client (GUI) coordinates to screen (desktop) coordinates
Func ClientToScreen($hWnd, ByRef $x, ByRef $y)
        Local $stPoint = DllStructCreate("int;int")

        DllStructSetData($stPoint, 1, $x)
        DllStructSetData($stPoint, 2, $y)

        DllCall("user32.dll", "int", "ClientToScreen", "hwnd", $hWnd, "ptr", DllStructGetPtr($stPoint))

        $x = DllStructGetData($stPoint, 1)
        $y = DllStructGetData($stPoint, 2)
        ; release Struct not really needed as it is a local
        $stPoint = 0
EndFunc   ;==>ClientToScreen


; Show at the given coordinates (x, y) the popup menu (hMenu) which belongs to a given GUI window (hWnd)
Func TrackPopupMenu($hWnd, $hMenu, $x, $y)
        DllCall("user32.dll", "int", "TrackPopupMenuEx", "hwnd", $hMenu, "int", 0, "int", $x, "int", $y, "hwnd", $hWnd, "ptr", 0)
EndFunc   ;==>TrackPopupMenu
发表于 2017-4-5 19:53:22 | 显示全部楼层
菜单美化谁会
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-11-17 04:54 , Processed in 0.072394 second(s), 20 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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