把button嵌入到状态栏中,点击的button没反应了【已解决】
本帖最后由 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
$y = $arPos + $arPos
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
跟踪$GUI_EVENT_PRIMARYDOWN,$GUI_EVENT_PRIMARYUP窗口消息 回复 2# afan
能不能说详细一点,有点不太明白 回复 3# xwt620 Case $OptionsBtn
ShowMenu($hGui, $msg, $OptionsContext)用下面的替换: Case $GUI_EVENT_PRIMARYUP
$Pos = GUIGetCursorInfo($hGui)
If $Pos = $OptionsBtn Then
ShowMenu($hGui, $msg, $OptionsContext)
EndIf但是在 ShowMenu 函数中发生错误,你再调试一下。 回复 4# xiehuahere
谢谢,需要改为
ShowMenu($hGui, $Pos, $OptionsContext)
发送控件ID,否则就出错
只不过我觉得应该为$GUI_EVENT_PRIMARYDOWN事件比较好。 雷锋精神传天下!谢谢分享!
页:
[1]