找回密码
 加入
搜索
查看: 4773|回复: 5

[GUI管理] 把button嵌入到状态栏中,点击的button没反应了【已解决】

  [复制链接]
发表于 2011-11-22 14:10:49 | 显示全部楼层 |阅读模式
本帖最后由 xwt620 于 2011-11-22 21:43 编辑

RT,如何解决这个问题,让button有响应
#include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>
#Include <GuiStatusBar.au3>

$hGui = GUICreate("My GUI", 300, 100)

$OptionsBtn = GUICtrlCreateButton("按钮选项", 10, 10)
$hButton = GUICtrlGetHandle($OptionsBtn)
$OptionsContext = GUICtrlCreateContextMenu(GUICtrlCreateDummy())
$Options1 = GUICtrlCreateMenuItem("选项1", $OptionsContext)
$Options2 = GUICtrlCreateMenuItem("选项2", $OptionsContext)
GUICtrlCreateMenuItem("", $OptionsContext)
$OptionsExit = GUICtrlCreateMenuItem("退出", $OptionsContext)

$hStatusBar = _GUICtrlStatusBar_Create($hGui)
_GUICtrlStatusBar_EmbedControl($hStatusBar, 0, $hButton,4)
GUISetState()
While 1
        $msg = GUIGetMsg()
        Switch $msg
                Case $OptionsExit, $GUI_EVENT_CLOSE
                        ExitLoop
                Case $OptionsBtn
                        ShowMenu($hGui, $msg, $OptionsContext)
                Case $Options1
                        MsgBox(64, "点击", "点击选项1")
                Case $Options2
                        MsgBox(64, "点击", "点击选项2")
        EndSwitch
WEnd
GUIDelete()

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

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

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
发表于 2011-11-22 15:56:01 | 显示全部楼层
跟踪$GUI_EVENT_PRIMARYDOWN,$GUI_EVENT_PRIMARYUP窗口消息
 楼主| 发表于 2011-11-22 21:05:41 | 显示全部楼层
回复 2# afan


    能不能说详细一点,有点不太明白
发表于 2011-11-22 21:26:34 | 显示全部楼层
回复 3# xwt620
    Case $OptionsBtn
              ShowMenu($hGui, $msg, $OptionsContext)
用下面的替换:
        Case $GUI_EVENT_PRIMARYUP
                $Pos = GUIGetCursorInfo($hGui)
                If $Pos[4] = $OptionsBtn Then
                        ShowMenu($hGui, $msg, $OptionsContext)
                EndIf
但是在 ShowMenu 函数中发生错误,你再调试一下。
 楼主| 发表于 2011-11-22 21:43:14 | 显示全部楼层
回复 4# xiehuahere


    谢谢,需要改为
ShowMenu($hGui, $Pos[4], $OptionsContext)
发送控件ID,否则就出错
只不过我觉得应该为$GUI_EVENT_PRIMARYDOWN事件比较好。
发表于 2014-5-6 06:53:30 | 显示全部楼层
雷锋精神传天下!谢谢分享!
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-11-16 23:40 , Processed in 0.076769 second(s), 23 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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