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

[网络通信] 【已解决】如何让button双击才执行程序呢?

[复制链接]
发表于 2018-10-17 10:28:55 | 显示全部楼层 |阅读模式
本帖最后由 229989799 于 2018-10-17 11:30 编辑

一般都是单击$Button1就执行程序,如何才能双击执行,单击不做任何操作。请问下大家。

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 615, 438, 192, 124)
$Button1 = GUICtrlCreateButton("Button1", 184, 160, 147, 57)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                case $Button1
                        MsgBox(0,"","你双击了button1")
                Case $GUI_EVENT_CLOSE
                        Exit

        EndSwitch
WEnd


多谢大神们解答。多谢三楼木子
发表于 2018-10-17 10:43:07 来自手机 | 显示全部楼层
加个变量记次
发表于 2018-10-17 11:17:15 | 显示全部楼层
本帖最后由 水木子 于 2018-10-17 11:25 编辑

#include <WinAPIex.au3>
#include <WindowsConstants.au3>

GUICreate('', 400, 300)
$Button1 = GUICtrlCreateButton('Button1', 100, 100, 200, 50)

$handle1 = DllCallbackRegister('_Button_Events', 'ptr', 'hwnd;uint;long;ptr')
$handle2 = _WinAPI_SetWindowLong(GUICtrlGetHandle($Button1), $GWL_WNDPROC, DllCallbackGetPtr($handle1))
GUISetState()

While 1
        Switch GUIGetMsg()
                Case $Button1
                        ;MsgBox(0, '测试', '左键点击')
                Case -3
                        GUIDelete()
                        DllCallbackFree($handle1)
                        Exit
        EndSwitch
WEnd

Func _Button_Events($hWnd, $uiMsg, $wParam, $lParam)
        Switch $uiMsg
                Case $WM_LBUTTONDBLCLK ; 左键双击
                        MsgBox(0, '', '你双击了button1')
                Case $WM_RBUTTONDOWN ; 右键按下
                        MsgBox(64, '', '鼠标右键点击')
        EndSwitch
        Return _WinAPI_CallWindowProc($handle2, $hWnd, $uiMsg, $wParam, $lParam)
EndFunc   ;==>_Button_Events

发表于 2018-10-17 11:32:22 | 显示全部楼层
#include <GUIConstants.au3>
Opt("MustDeclareVars", 1)

Global Const $DebugIt = 1
;~ Global Const $WM_COMMAND = 0x0111
Global $Hovered = 0
Global $Button, $status, $Label

_Main()

Func _Main()
    Local $x = 48, $y = 88, $msg, $Form2

    $Form2 = GUICreate("Blash", 716, 561, 155, 134, BitOR($WS_MAXIMIZEBOX, $WS_SIZEBOX, $WS_THICKFRAME, $WS_OVERLAPPEDWINDOW, $WS_TILEDWINDOW, $WS_TABSTOP))

    $Button = GUICtrlCreateButton("Button Test", 10, 10, 89, 41, $BS_NOTIFY)
    $Label = GUICtrlCreateLabel("Label Test", 10, 60, 120, 22, BitOR($SS_NOTIFY, $SS_SUNKEN, $SS_CENTER))
    
    GUIRegisterMsg($WM_COMMAND, "MY_WM_COMMAND")
    GUISetState(@SW_SHOW)
    While 1
        $msg = GUIGetMsg()
        Select
            Case $msg = $GUI_EVENT_CLOSE
                ExitLoop
        EndSelect
    WEnd
EndFunc   ;==>_Main

Func Button_Click(ByRef $ctrl_id)
;~  _DebugPrint("Button_Click")
EndFunc   ;==>Button_Click

Func Button_DblClick(ByRef $ctrl_id)
;~  _DebugPrint("Button_DblClick")
    MsgBox(0, "Test", "Button_DblClick")
EndFunc   ;==>Button_DblClick

Func Label_Click(ByRef $ctrl_id)
    _DebugPrint("Label_Click")
EndFunc   ;==>Label_Click

Func Label_DblClick(ByRef $ctrl_id)
;~  _DebugPrint("Button_DblClick")
    MsgBox(0, "Test", "Label_DblClick")
EndFunc   ;==>Label_DblClick

Func _LoWord($x)
    Return BitAND($x, 0xFFFF)
EndFunc   ;==>_LoWord

Func _HiWord($x)
    Return BitShift($x, 16)
EndFunc   ;==>_HiWord

Func MY_WM_COMMAND($hWnd, $msg, $wParam, $lParam)
    Local Const $BN_CLICKED = 0;
    Local Const $BN_PAINT = 1;
    Local Const $BN_HILITE = 2;
    Local Const $BN_PUSHED = $BN_HILITE;
    Local Const $BN_UNHILITE = 3;
    Local Const $BN_UNPUSHED = $BN_UNHILITE;
    Local Const $BN_DISABLE = 4;
    Local Const $BN_DOUBLECLICKED = 5;
    Local Const $BN_DBLCLK = $BN_DOUBLECLICKED;
    Local Const $BN_SETFOCUS = 6;
    Local Const $BN_KILLFOCUS = 7;

    Local Const $STN_CLICKED = 0
    Local Const $STN_DBLCLK = 1
    Local Const $STN_DISABLE = 3
    Local Const $STN_ENABLE = 2

    Local $nNotifyCode = _HiWord($wParam)
    Local $nID = _LoWord($wParam)
    Local $hCtrl = $lParam
    
    If $nID <> 2 Then
        Switch $nID
            Case $Button
                Switch $nNotifyCode
                    Case $BN_CLICKED
                        _DebugPrint("$BN_CLICKED: " & @LF & "GUIHWnd" & @TAB & ":" & $hWnd & @LF & _
                                "MsgID" & @TAB & ":" & $msg & @LF & _
                                "wParam" & @TAB & ":" & $wParam & @LF & _
                                "lParam" & @TAB & ":" & $lParam & @LF & @LF & _
                                "WM_COMMAND - Infos:" & @LF & _
                                "-----------------------------" & @LF & _
                                "Code" & @TAB & ":" & $nNotifyCode & @LF & _
                                "CtrlID" & @TAB & ":" & $nID & @LF & _
                                "CtrlHWnd" & @TAB & ":" & $hCtrl)
                        Button_Click($nID)
                    Case $BN_PAINT
                        _DebugPrint("$BN_PAINT")
                    Case $BN_PUSHED, $BN_HILITE
                        _DebugPrint("$BN_PUSHED, $BN_HILITE")
                    Case $BN_UNPUSHED, $BN_UNHILITE
                        _DebugPrint("$BN_UNPUSHED")
                    Case $BN_DISABLE
                        _DebugPrint("$BN_DISABLE")
                    Case $BN_DBLCLK, $BN_DOUBLECLICKED
;~                       _DebugPrint("$BN_DBLCLK, $BN_DOUBLECLICKED")
                        _DebugPrint("$BN_CLICKED: " & @LF & "GUIHWnd" & @TAB & ":" & $hWnd & @LF & _
                                "MsgID" & @TAB & ":" & $msg & @LF & _
                                "wParam" & @TAB & ":" & $wParam & @LF & _
                                "lParam" & @TAB & ":" & $lParam & @LF & @LF & _
                                "WM_COMMAND - Infos:" & @LF & _
                                "-----------------------------" & @LF & _
                                "Code" & @TAB & ":" & $nNotifyCode & @LF & _
                                "CtrlID" & @TAB & ":" & $nID & @LF & _
                                "CtrlHWnd" & @TAB & ":" & $hCtrl)
                        Button_DblClick($nID)
                    Case $BN_SETFOCUS
                        _DebugPrint("$BN_SETFOCUS")
                    Case $BN_KILLFOCUS
                        _DebugPrint("$BN_KILLFOCUS")
                EndSwitch
            Case $Label
                Switch $nNotifyCode
                    Case $STN_CLICKED
;~                       _DebugPrint("$STN_CLICKED: " & @LF & "GUIHWnd" & @TAB & ":" & $hwnd & @LF & _
;~                                                                  "MsgID" & @TAB & ":" & $Msg & @LF & _
;~                                                                  "wParam" & @TAB & ":" & $wParam & @LF & _
;~                                                                  "lParam" & @TAB & ":" & $lParam & @LF & @LF & _
;~                                                                  "WM_COMMAND - Infos:" & @LF & _
;~                                                                  "-----------------------------" & @LF & _
;~                                                                  "Code" & @TAB & ":" & $nNotifyCode & @LF & _
;~                                                                  "CtrlID" & @TAB & ":" & $nID & @LF & _
;~                                                                  "CtrlHWnd" & @TAB & ":" & $hCtrl)
                        Label_Click($nID)
                    Case $STN_DISABLE
                        _DebugPrint("$STN_DISABLE")
                    Case $STN_ENABLE
                        _DebugPrint("$STN_ENABLE")
                    Case $STN_DBLCLK
;~                       _DebugPrint("$STN_DBLCLK")
                        _DebugPrint("$STN_DBLCLK: " & @LF & "GUIHWnd" & @TAB & ":" & $hWnd & @LF & _
                                "MsgID" & @TAB & ":" & $msg & @LF & _
                                "wParam" & @TAB & ":" & $wParam & @LF & _
                                "lParam" & @TAB & ":" & $lParam & @LF & @LF & _
                                "WM_COMMAND - Infos:" & @LF & _
                                "-----------------------------" & @LF & _
                                "Code" & @TAB & ":" & $nNotifyCode & @LF & _
                                "CtrlID" & @TAB & ":" & $nID & @LF & _
                                "CtrlHWnd" & @TAB & ":" & $hCtrl)
                        Label_DblClick($nID)
                EndSwitch
        EndSwitch
    EndIf
    ; Proceed the default Autoit3 internal message commands.
    ; You also can complete let the line out.
    ; !!! But only 'Return' (without any value) will not proceed
    ; the default Autoit3-message in the future !!!
;~     Return $GUI_RUNDEFMSG
EndFunc   ;==>MY_WM_COMMAND

Func _DebugPrint($s_text)
    $s_text = StringReplace($s_text, @LF, @LF & "-->")
    ConsoleWrite( _
            "!===========================================================" & @LF & _
            "+===========================================================" & @LF & _
            "-->" & $s_text & @LF & _
            "+===========================================================" & @LF)
EndFunc   ;==>_DebugPrint

您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-4-19 22:17 , Processed in 0.072043 second(s), 19 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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