找回密码
 加入
搜索
楼主: xiezhang6263

[AU3基础] 如何实现按钮下拉菜单?(已解决)

 火... [复制链接]
发表于 2011-5-21 20:49:20 | 显示全部楼层
回复 15# xiezhang6263
#include <GUIConstantsEx.au3>
#include <GuiMenu.au3>
#include <WindowsConstants.au3>
 
Opt("GUICoordMode", 1)
$hGUI = GUICreate("Menu", 400, 300)
Global Const $idButton = GUICtrlCreateButton("Test", 100, 100, 80, 40)
Global Const $idButton1 = GUICtrlCreateButton("Test-1", 300, 100, 80, 40)
Global Enum $idNew = 1000, $idOpen, $idClose, $idExit
Global Enum $idNew1 = 2000, $idOpen1, $idClose1, $idExit1
Global $hMenu
$hMenu = _GUICtrlMenu_CreatePopup()
Assign($idButton,$hMenu)
_GUICtrlMenu_InsertMenuItem ($hMenu, 0, "新建文件", $idNew)
_GUICtrlMenu_InsertMenuItem ($hMenu, 1, "", 0)
_GUICtrlMenu_InsertMenuItem ($hMenu, 2, "打开文件", $idOpen)
_GUICtrlMenu_InsertMenuItem ($hMenu, 3, "关闭文件", $idClose)
_GUICtrlMenu_InsertMenuItem ($hMenu, 4, "", 0)
_GUICtrlMenu_InsertMenuItem ($hMenu, 5, "退出", $idExit)


$hMenu1 = _GUICtrlMenu_CreatePopup()
Assign($idButton1,$hMenu1)
_GUICtrlMenu_InsertMenuItem ($hMenu1, 0, "新建文件-button1", $idNew1)
_GUICtrlMenu_InsertMenuItem ($hMenu1, 1, "", 0)
_GUICtrlMenu_InsertMenuItem ($hMenu1, 2, "打开文件-button1", $idOpen1)
_GUICtrlMenu_InsertMenuItem ($hMenu1, 3, "关闭文件-button1", $idClose1)
_GUICtrlMenu_InsertMenuItem ($hMenu1, 4, "", 0)
_GUICtrlMenu_InsertMenuItem ($hMenu1, 5, "退出-button1", $idExit1)

GUISetState()
 
GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
 
While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            _GUICtrlMenu_DestroyMenu($hMenu)
            GUIDelete()
            Exit
        Case $idButton
            ShowMenu($hGUI,$idButton)
                Case $idButton1
            ShowMenu($hGUI,$idButton1)
    EndSwitch
WEnd
 
Func New()
    MsgBox(0, "信息", "新建文件")
EndFunc
 
Func Open()
    MsgBox(0, "信息", "打开")    
EndFunc
 
Func Close()
    MsgBox(0, "信息", "关闭")    
EndFunc

Func New1()
    MsgBox(0, "信息", "新建文件-1")
EndFunc
 
Func Open1()
    MsgBox(0, "信息", "打开-1")    
EndFunc
 
Func Close1()
    MsgBox(0, "信息", "关闭-1")    
EndFunc

Func ShowMenu($hWnd,$id)
    Local $aButton = ControlGetPos("", "", $id)
    Local $x = $aButton[0]
    Local $y = $aButton[1] + $aButton[3]
    ClientToScreen($hGUI, $x, $y)        
                _GUICtrlMenu_TrackPopupMenu(Eval($id), $hWnd, $x, $y)                        
    Return True
EndFunc   ;==>WM_CONTEXTMENU
 
Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)
    Switch $iwParam
         Case $idNew
                        New()
        Case $idOpen
            Open()
        Case $idClose
            Close()
        Case $idExit
            Exit
                Case $idNew1
                        New1()
        Case $idOpen1
            Open1()
        Case $idClose1
            Close1()
        Case $idExit1
            Exit        
    EndSwitch
EndFunc
 
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)
    $stPoint = 0
EndFunc   ;==>ClientToScreen
发表于 2011-6-29 01:53:43 | 显示全部楼层
支持3笑兄.分享快乐!
发表于 2011-7-17 10:21:05 | 显示全部楼层
学习了,以前搞过一个
发表于 2011-8-7 13:39:18 | 显示全部楼层
dummy 不正是这个么。。。
发表于 2012-2-7 02:47:40 | 显示全部楼层
学习了,代码很有价值
发表于 2012-4-30 10:35:34 | 显示全部楼层
谢谢 3mile 谢谢了~~~~~
发表于 2012-5-1 20:43:12 | 显示全部楼层
认真学习了,谢谢楼主分享!
发表于 2012-5-14 16:08:23 | 显示全部楼层
谢谢。学习了
发表于 2012-5-30 07:25:49 | 显示全部楼层
非常感谢 3mile
发表于 2012-5-30 09:02:31 | 显示全部楼层
初来咋到,看不懂,先收藏...
发表于 2012-6-2 02:11:44 | 显示全部楼层
代码精湛啊
发表于 2018-12-20 16:38:43 | 显示全部楼层
多谢分享,学习中......
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-5-16 20:19 , Processed in 0.079998 second(s), 14 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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