本帖最后由 cashiba 于 2019-8-31 08:56 编辑
#include <GUIConstantsEx.au3>
Global $hGUI,$idStart
Example()
Func Example()
$hGUI = GUICreate("TEST", 300, 200)
$idStart = GUICtrlCreateButton("记事本", 120, 170, 85, 25)
Local $idClose = GUICtrlCreateButton("关 闭", 210, 170, 85, 25)
GUISetState(@SW_SHOW, $hGUI)
Local $iPID = 0
While 1
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE, $idClose
ExitLoop
Case $idStart
_ButtonToggle()
EndSwitch
WEnd
GUIDelete($hGUI)
If $iPID Then ProcessClose($iPID)
EndFunc ;==>Example
Func _ButtonToggle()
While 1
Local $a = GUIGetCursorInfo($hGui)
If $a[4] = $idStart Then
if $a[3] = 1 then
ConsoleWrite("鼠标右键按下" & @CRLF)
If GUICtrlRead($idStart) = "记事本" Then
GUICtrlSetData($idStart, "计算器")
ElseIf GUICtrlSetData($idStart, "计算器") Then
GUICtrlSetData($idStart, "记事本")
EndIf
ElseIf $a[2] = 1 then
ConsoleWrite("鼠标左键按下" & @CRLF)
If GUICtrlRead($idStart) = "记事本" Then
$iPID = Run("notepad.exe", "", @SW_SHOWMAXIMIZED)
ElseIf GUICtrlRead($idStart) = "计算器" Then
$iPID = Run("calc.exe", "", @SW_SHOWMAXIMIZED)
EndIf
EndIf
Else
ExitLoop
EndIf
sleep(100)
WEnd
EndFunc ;==>_ButtonToggle
如上,想实现一个按钮左右开弓,一键多能:右击切换计算器和记事本,左击打开
按上述写法容易卡壳
想用按钮消息来实现,发现按钮的消息里没有右击
用鼠标事件绑定按钮,不是太熟悉,似乎也不好用
请大神们指点一下....
预谢!
|