input控件事件添加[已解决]
本帖最后由 heroxianf 于 2019-2-20 15:18 编辑如下面代码,我想给INPUT控件添加一个事件,起作用的是注释的那部分,我想改成事件模式,而且不管是禁用还是开启 都能触发左键或者右键单击事件,这个怎么弄呢?
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
$Form1 = GUICreate("Form1", 615, 438, 192, 124)
GUISetOnEvent($GUI_EVENT_CLOSE, "Test")
$Input1 = GUICtrlCreateInput("Input1", 152, 112, 285, 21)
GUISetState(@SW_SHOW)
Opt("GUIOnEventMode", 1) ;主界面菜单事件模式
While 1
Sleep(100)
;~ $Info = GUIGetCursorInfo($Form1)
;~ If $Info = $Input1 And $Info Then
;~ $s = GUICtrlGetState($Input1) ; 控件在灰色禁用状态才复制链接
;~ If $s = 144 Then
;~ MsgBox(0, '', '处于禁用灰色状态')
;~ Else
;~ MsgBox(0, '', '处于编辑状态')
;~ EndIf
;~ EndIf
WEnd
Func Test()
$nMsg = @GUI_CtrlId
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Input1
MsgBox(0, '', '')
EndSwitch
EndFunc ;==>Test
寫在 鼠標的事件裡吧
http://www.autoitx.com/forum.php?mod=viewthread&tid=2010&extra=page%3D8
鼠標 事件 #include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Constants.au3>
#include <GuiImageList.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <FontConstants.au3>
Opt("GUIOnEventMode", 1) ;主界面菜?事件模式
$Form1 = GUICreate("Form1", 615, 438, 192, 124)
GUISetOnEvent($GUI_EVENT_CLOSE, "Test")
$Input2 = GUICtrlCreateLabel("", 152, 112, 285, 21)
$Input1 = GUICtrlCreateInput("Input1", 152, 112, 285, 21)
GUISetState(@SW_SHOW)
GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
GUICtrlSetOnEvent($Input1,"Test")
While 1
SLEEP(10)
WEnd
Func Test()
ConsoleWrite("A")
Switch @GUI_CtrlId
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
EndFunc ;==>Test
Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)
#forceref $hWnd, $iMsg, $iwParam, $ilParam
Local $hWndFrom, $iIDFrom, $iCode
$hWndFrom = $ilParam
$iIDFrom = BitAND($iwParam, 0xFFFF) ; Low Word
$iCode = BitShift($iwParam, 16) ; Hi Word
Switch $hWnd
Case $Form1
If$iIDFrom= $Input2 Then
Local $result = DllCall("User32.dll", "dword", "GetWindowLong", "hwnd", GUICtrlGetHandle($Input1), "int", $GWL_STYLE)
If BitAND($result, $ES_READONLY) = $ES_READONLY Then
MsgBox(0,"A","唯讀")
Else
MsgBox(0,"","可寫")
EndIf
EndIf
EndSwitch
EndFunc
kk_lee69 发表于 2019-2-20 12:04
KK有没有收藏完整的写法,就是检测鼠标的左右键单击、双击事件。 来学习一下。 heroxianf 发表于 2019-2-20 13:42
KK有没有收藏完整的写法,就是检测鼠标的左右键单击、双击事件。
你需要甚麼上面案例不是有了嗎你實際跑 在INPUT 控件上 點一下就會告訴你現在INPUT控件是 可以寫 還是不可以寫 heroxianf 发表于 2019-2-20 13:42
KK有没有收藏完整的写法,就是检测鼠标的左右键单击、双击事件。
不要使用 禁用使用 狀態唯讀 kk_lee69 发表于 2019-2-20 14:48
你需要甚麼上面案例不是有了嗎你實際跑 在INPUT 控件上 點一下就會告訴你現在INPUT控件是 可 ...
我想对一个控件 写一些功能,比如对一个INPUT我想单击左键触发一个事件,双击左键触发一个事件、单击右键触发一个事件、双击右键触发一个事件。我记得之前找到过一个案例非常齐全,现在找不到了。 heroxianf 发表于 2019-2-20 14:56
我想对一个控件 写一些功能,比如对一个INPUT我想单击左键触发一个事件,双击左键触发一个事件、单击右键 ...
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GuiComboBoxEx.au3>
#region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 500, 300)
$Label1 = GUICtrlCreateLabel("GUICtrlCreateCombo生成", 60, 66, 200, 17)
$Combo1 = GUICtrlCreateCombo("Combo1", 250, 64, 177, 25, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL))
$Label2 = GUICtrlCreateLabel("_GUICtrlComboBox_Create生成", 60, 111, 200, 17)
$Combo2 = _GUICtrlComboBox_Create($Form1, "Combo2", 250, 109, 177, 25)
_SendMessage($Combo2, $CB_SETCURSEL, 0)
$Label3 = GUICtrlCreateLabel("_GUICtrlComboBoxEx_Create生成", 60, 162, 200, 17)
$Combo3 = _GUICtrlComboBoxEx_Create($Form1, "Combo3|a|b|c", 250, 160, 177)
_SendMessage($Combo3, $CB_SETCURSEL, 0)
GUISetState(@SW_SHOW)
#endregion ### END Koda GUI section ###
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
WEnd
;###########################################
Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)
#forceref $hWnd, $iMsg
Local $hWndFrom, $iIDFrom, $iCode
$hWndFrom = $ilParam
$iIDFrom = BitAND($iwParam, 0xFFFF) ; Low Word
$iCode = BitShift($iwParam, 16) ; Hi Word
Switch $iIDFrom
Case $Combo1
Switch $iCode
Case $CBN_KILLFOCUS
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $Combo1 - $CBN_KILLFOCUS' & @CRLF)
Case $CBN_SETFOCUS
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $Combo1 - $CBN_SETFOCUS' & @CRLF)
Case $CBN_EDITCHANGE
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $Combo1 - $CBN_EDITCHANGE' & @CRLF)
Case $CBN_SELCHANGE
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $Combo1 - $CBN_SELCHANGE' & @CRLF)
Case $CBN_SELENDCANCEL
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $Combo1 - $CBN_SELENDCANCEL' & @CRLF)
Case $CBN_EDITUPDATE
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $Combo1 - $CBN_EDITUPDATE' & @CRLF)
Case $CBN_DROPDOWN
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $Combo1 - $CBN_DROPDOWN' & @CRLF)
Case $CBN_CLOSEUP
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $Combo1 - $CBN_CLOSEUP' & @CRLF)
Case $CBN_SELENDOK
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $Combo1 - $CBN_SELENDOK' & @CRLF)
Case Else
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $Combo1 - $iCode = ' & $iCode & @CRLF)
EndSwitch
ConsoleWrite('===========================================================================' & @CRLF)
EndSwitch
Switch $hWndFrom
Case $Combo2
Switch $iCode
Case $CBN_KILLFOCUS
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $Combo2 - $CBN_KILLFOCUS' & @CRLF)
Case $CBN_SETFOCUS
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $Combo2 - $CBN_SETFOCUS' & @CRLF)
Case $CBN_EDITCHANGE
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $Combo2 - $CBN_EDITCHANGE' & @CRLF)
Case $CBN_SELCHANGE
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $Combo2 - $CBN_SELCHANGE' & @CRLF)
Case $CBN_SELENDCANCEL
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $Combo2 - $CBN_SELENDCANCEL' & @CRLF)
Case $CBN_EDITUPDATE
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $Combo2 - $CBN_EDITUPDATE' & @CRLF)
Case $CBN_DROPDOWN
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $Combo2 - $CBN_DROPDOWN' & @CRLF)
Case $CBN_CLOSEUP
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $Combo2 - $CBN_CLOSEUP' & @CRLF)
Case $CBN_SELENDOK
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $Combo2 - $CBN_SELENDOK' & @CRLF)
Case Else
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $Combo2 - $iCode = ' & $iCode & @CRLF)
EndSwitch
ConsoleWrite('===========================================================================' & @CRLF)
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_COMMAND
;###########################################
Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
#forceref $hWnd, $iMsg, $iwParam
Local $tNMHDR, $hWndFrom, $iIDFrom, $iCode
$tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
$hFrom = DllStructGetData($tNMHDR, "hWndFrom")
$iCode = DllStructGetData($tNMHDR, "Code")
Switch $hFrom
Case $Combo3
Switch $iCode
Case $NM_KILLFOCUS;CBEM_KILLCOMBOFOCUS
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $Combo3 - $NM_KILLFOCUS' & @CRLF)
;疑問:為什麼ComboBoxEx不接收$NM_KILLFOCUS消息[已解決]
;https://msdn.microsoft.com/en-us/library/windows/desktop/bb775784(v=vs.85).aspx
Case $NM_SETFOCUS;CBEM_SETCOMBOFOCUS
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $Combo3 - $NM_SETFOCUS' & @CRLF)
;疑問:為什麼ComboBoxEx不接收$NM_SETFOCUS消息[已解決]
;https://msdn.microsoft.com/en-us/library/windows/desktop/bb775785(v=vs.85).aspx
Case $NM_SETCURSOR
Case $CBEN_GETDISPINFOW
Case $CBEN_BEGINEDIT
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $Combo3 - $CBEN_BEGINEDIT' & @CRLF)
Case $CBEN_ENDEDITW
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $Combo3 - $CBEN_ENDEDITW' & @CRLF)
Local $tNMCBEENDEDIT = DllStructCreate($tagNMCBEENDEDIT, $ilParam)
Local $fChanged = DllStructGetData($tNMCBEENDEDIT, "fChanged")
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $fChanged = ' & $fChanged & @CRLF)
Local $NewSelection = DllStructGetData($tNMCBEENDEDIT, "NewSelection")
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $NewSelection = ' & $NewSelection & @CRLF)
Local $szText = DllStructGetData($tNMCBEENDEDIT, "szText")
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $szText = ' & $szText & @CRLF)
Local $Why = DllStructGetData($tNMCBEENDEDIT, "Why")
Switch $Why
Case 4
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $Why = CBENF_DROPDOWN' & @CRLF) ;(用戶啟動下拉清單)
Case 1
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $Why = CBENF_KILLFOCUS' & @CRLF) ;(編輯方塊失去鍵盤焦點)
;***********************************************************
Case 2
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $Why = CBENF_ESCAPE' & @CRLF) ;(用戶按了ESC)
Case 3
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $Why = CBENF_RETURN' & @CRLF) ;(用戶完成編輯操作按回車)
Case Else
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $Combo3 - $CBEN_ENDEDITW - $Why = ' & $iCode & @CRLF)
;參見幫助的 $tagNMCBEENDEDIT
;參見MSDN的 https://msdn.microsoft.com/en-us/library/windows/desktop/bb775760(v=vs.85).aspx
;參見MSDN的 https://msdn.microsoft.com/en-us/library/windows/desktop/bb775750(v=vs.85).aspx
;問題: 為什麼$CBEN_ENDEDITW消息只回應了(CBENF_DROPDOWN)和(CBENF_KILLFOCUS)
; msdn上定義的(CBENF_ESCAPE)和(CBENF_RETURN)沒有回應?
; ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑
; 這些(CBENF_DROPDOWN,CBENF_KILLFOCUS,CBENF_ESCAPE,CBENF_RETURN)的具體值是多少呢?貌似AU3裡面沒有定義,網上也找不到
; (找不到也許是我能力不足問題)(以上$Why的1,2,3,4值是我蒙的)
; =====================================================
; 之所以(CBENF_ESCAPE)和(CBENF_RETURN)沒有回應是AU3的問題嗎,用其他語言寫有回應嗎?請大神試一下!
; 假設其他語言也無效這個是ComboBoxEx本身的問題,我們有沒有方法讓控制項回應CBENF_RETURN和CBENF_ESCAPE呢?
; =====================================================
; 題外話
; 如果說WM_NOTIFY是比WM_COMMAND相對更高級的消息,ComboBoxEx是比ComboBox相對更高級的控制項
; 為什麼ComboBoxEx只發送這麼少量的通知,不像ComboBox那樣擁有相對全面的通知,微軟是怎麼想的?(如下)
; (CBN_CLOSEUP,CBN_DBLCLK,CBN_DROPDOWN,CBN_EDITCHANGE,CBN_EDITUPDATE,CBN_ERRSPACE)
; (CBN_KILLFOCUS,CBN_SELCHANGE,CBN_SELENDCANCEL,CBN_SELENDOK,CBN_SETFOCUS)
;***********************************************************
EndSwitch
ConsoleWrite('===========================================================================' & @CRLF)
Case Else
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $Combo3 - $iCode = ' & $iCode & @CRLF)
;ComboBoxEx你就不能發送多點通知麼,我,我~~
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_NOTIFY
;###########################################
heroxianf 发表于 2019-2-20 14:56
我想对一个控件 写一些功能,比如对一个INPUT我想单击左键触发一个事件,双击左键触发一个事件、单击右键 ...
#include <GuiComboBox.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Global $g_idCombo
Example()
Func Example()
; Create GUI
GUICreate("ComboBox Auto Complete", 400, 296)
$g_idCombo = GUICtrlCreateCombo("", 2, 2, 396, 296)
GUISetState(@SW_SHOW)
; Add files
_GUICtrlComboBox_BeginUpdate($g_idCombo)
_GUICtrlComboBox_AddDir($g_idCombo, @WindowsDir & "\*.exe")
_GUICtrlComboBox_EndUpdate($g_idCombo)
GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
; Loop until the user exits.
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
GUIDelete()
EndFunc ;==>Example
Func _Edit_Changed()
_GUICtrlComboBox_AutoComplete($g_idCombo)
EndFunc ;==>_Edit_Changed
Func WM_COMMAND($hWnd, $iMsg, $wParam, $lParam)
#forceref $hWnd, $iMsg
Local $hWndFrom, $iIDFrom, $iCode, $hWndCombo
If Not IsHWnd($g_idCombo) Then $hWndCombo = GUICtrlGetHandle($g_idCombo)
$hWndFrom = $lParam
$iIDFrom = BitAND($wParam, 0xFFFF) ; Low Word
$iCode = BitShift($wParam, 16) ; Hi Word
Switch $hWndFrom
Case $g_idCombo, $hWndCombo
Switch $iCode
Case $CBN_CLOSEUP ; Sent when the list box of a combo box has been closed
_DebugPrint("$CBN_CLOSEUP" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _
"-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _
"-->Code:" & @TAB & $iCode)
; no return value
Case $CBN_DBLCLK ; Sent when the user double-clicks a string in the list box of a combo box
_DebugPrint("$CBN_DBLCLK" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _
"-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _
"-->Code:" & @TAB & $iCode)
; no return value
Case $CBN_DROPDOWN ; Sent when the list box of a combo box is about to be made visible
_DebugPrint("$CBN_DROPDOWN" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _
"-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _
"-->Code:" & @TAB & $iCode)
; no return value
Case $CBN_EDITCHANGE ; Sent after the user has taken an action that may have altered the text in the edit control portion of a combo box
_DebugPrint("$CBN_EDITCHANGE" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _
"-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _
"-->Code:" & @TAB & $iCode)
_Edit_Changed()
; no return value
Case $CBN_EDITUPDATE ; Sent when the edit control portion of a combo box is about to display altered text
_DebugPrint("$CBN_EDITUPDATE" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _
"-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _
"-->Code:" & @TAB & $iCode)
; no return value
Case $CBN_ERRSPACE ; Sent when a combo box cannot allocate enough memory to meet a specific request
_DebugPrint("$CBN_ERRSPACE" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _
"-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _
"-->Code:" & @TAB & $iCode)
; no return value
Case $CBN_KILLFOCUS ; Sent when a combo box loses the keyboard focus
_DebugPrint("$CBN_KILLFOCUS" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _
"-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _
"-->Code:" & @TAB & $iCode)
; no return value
Case $CBN_SELCHANGE ; Sent when the user changes the current selection in the list box of a combo box
_DebugPrint("$CBN_SELCHANGE" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _
"-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _
"-->Code:" & @TAB & $iCode)
; no return value
Case $CBN_SELENDCANCEL ; Sent when the user selects an item, but then selects another control or closes the dialog box
_DebugPrint("$CBN_SELENDCANCEL" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _
"-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _
"-->Code:" & @TAB & $iCode)
; no return value
Case $CBN_SELENDOK ; Sent when the user selects a list item, or selects an item and then closes the list
_DebugPrint("$CBN_SELENDOK" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _
"-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _
"-->Code:" & @TAB & $iCode)
; no return value
Case $CBN_SETFOCUS ; Sent when a combo box receives the keyboard focus
_DebugPrint("$CBN_SETFOCUS" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _
"-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _
"-->Code:" & @TAB & $iCode)
; no return value
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_COMMAND
Func _DebugPrint($s_Text, $sLine = @ScriptLineNumber)
ConsoleWrite( _
"!===========================================================" & @CRLF & _
"+======================================================" & @CRLF & _
"-->Line(" & StringFormat("%04d", $sLine) & "):" & @TAB & $s_Text & @CRLF & _
"+======================================================" & @CRLF)
EndFunc ;==>_DebugPrint
kk_lee69 发表于 2019-2-20 15:16
QQQ 就是这个了。
页:
[1]